diff --git a/01_Day_JavaScript_Refresher/01_javascript_refresher/Function Exercises/level1.js b/01_Day_JavaScript_Refresher/01_javascript_refresher/Function Exercises/level1.js new file mode 100644 index 0000000..5bfbd25 --- /dev/null +++ b/01_Day_JavaScript_Refresher/01_javascript_refresher/Function Exercises/level1.js @@ -0,0 +1,55 @@ +function fullName(firstName, lastName) { + return `${firstName} ${lastName}`; +} + +function addNumbers(num1, num2) { + return num1 + num2; +} + +function _areaOfCircle(radius) { + return Math.PI * radius * radius; +} + +function convertCelciusToFahrenheit(celsius) { + return (celsius * 1.8) + 32; +} + +function bmi(bmi, height = 1) { + // if bmi only is submitted, bmi will be used as the bmi + let bmi = weigth / (height * height); + + if (bmi < 18.5) { + console.log("Underweight"); + } else if (bmi < 24.9) { + console.log("Normal weight"); + } else if (bmi < 29.9) { + console.log("Overweight"); + } else { + console.log("Obese"); + } + + return bmi; +} + +function checkSeason(month) { + seasons = { + winter: ["december", "january", "february"], + spring: ["march", "april", "may"], + summer: ["june", "july", "august"], + autumn: ["september", "october", "november"] + }; + month = month.toLowerCase(); + + for (const season in seasons) { + if (Object.hasOwnProperty.call(seasons, season)) { + const months = seasons[season]; + months.forEach(m => { + if (m == month) { + return season; + } + }); + } + } + console.log("There is no such month"); + return "noSeason"; +} \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/01_javascript_refresher/Function Exercises/level2.js b/01_Day_JavaScript_Refresher/01_javascript_refresher/Function Exercises/level2.js new file mode 100644 index 0000000..7473640 --- /dev/null +++ b/01_Day_JavaScript_Refresher/01_javascript_refresher/Function Exercises/level2.js @@ -0,0 +1,80 @@ +function solveQuadEquation(a, b, c) { + const inSquare = (b * b) - (4 * a * c); + if (inSquare < 0) { + console.log("No real solutions"); + return; + } + const lower = (-b - inSquare) / (2 * a); + const higher = (-b + inSquare) / (2 * a); + return {lower, higher}; +} + +function printArray(arr) { + arr.forEach(elem => { + console.log(elem); + }); +} + +function showDateTime() { + const format = { + year: "numeric", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit" + }; + console.log(Intl.DateTimeFormat(undefined, format).format(new Date()).replace(',', '')); +} + +function swapValues(x, y) { + return [y, x]; // ??? +} + +function reverseArray(arr) { + const newArray = Array(arr.length); + arr.forEach((elem, index, arrayCopy) => { + newArray[arrayCopy.length - index - 1] = elem; + }); + return newArray; +} + +function capitalizeArray(arr) { + arr.forEach((elem, index) => { + arr[index] = elem.toUpperCase(); + }) + return arr; +} + +function addItem(item, arr) { + arr.push(item); + return arr; +} + +function removeItem(index, arr) { + arr.splice(index,1); + return arr; +} + +function evensAndOdds(val) { + let [evens, odds] = [Math.floor(val/2), Math.round(val/2)]; + console.log(`There are ${odds} odds`); + console.log(`There are ${evens} evens`); +} // this will not count 0 as an even number as not positive + +function sum() { + let sum = 0; + for (let i = 0; i < arguments.length; i++) { + sum += arguments[i]; + } + return sum; +} + +function userIdGenerator() { + const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + result = ""; + for (let i = 0; i < 7; i++) { + result += chars[Math.floor(Math.random() * chars.length)]; + } + console.log(result); + return result; +} \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/01_javascript_refresher/Function Exercises/level3.html b/01_Day_JavaScript_Refresher/01_javascript_refresher/Function Exercises/level3.html new file mode 100644 index 0000000..e69de29 diff --git a/01_Day_JavaScript_Refresher/01_javascript_refresher/Function Exercises/level3.js b/01_Day_JavaScript_Refresher/01_javascript_refresher/Function Exercises/level3.js new file mode 100644 index 0000000..e69de29