From aeb4f254bb7b35a2e7ed9678ca7e41b30cc207b6 Mon Sep 17 00:00:00 2001 From: Daliz Cruz Date: Tue, 8 Dec 2020 19:53:56 -0500 Subject: [PATCH 1/2] variables lab --- problems/variables.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/problems/variables.js b/problems/variables.js index 831a97c..417614d 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -2,27 +2,54 @@ // Age Calculator: // * Store your birth year in a constant variable. +const myBirthYear= 1991; +console.log (myBirthYear); // * Store a future year in a variable. +let futureYear= 2020; +console.log (futureYear); // * Calculate your 2 possible ages for that year based on the stored values. // * For example, if you were born in 1988, then in 2026 you'll be either 37 or 38, depending on what month it is in 2026. // * Log them to the screen like so: "I will be either `ageMin` or `ageMax` in `futureYear`", substituting the values. +let ageMax= futureYear - myBirthYear; +let ageMin= ageMax -1; +console.log (ageMax); +console.log (ageMin); +console.log (`I will be either ${ageMax} or ${ageMin} in ${futureYear}.`); // ## Problem Two // Snack Supply Calculator: // * Store your current age in a variable. +let myAge= 29; +console.log (myAge); // * Store a maximum age in a constant variable. +const maxAge= 50; +console.log (maxAge); // * Store an estimated snack amount per day (as a number). +let snackEstmt= 2; +console.log (snackEstmt); // * Calculate how many snacks you would eat total, from your current age until the maximum age. +let snacksAtAge= snackEstmt * 365 * (maxAge - myAge); +console.log (snacksAtAge); // * Log the result to the screen like this: "You will need `snackNumber` to last you until the age of `maxAge`". +console.log (`You will need ${snacksAtAge} to last you until the age of ${maxAge}.`); // ## Problem Three - // Calculate properties of a circle, using the definitions: http://math2.org/math/geometry/circles.htm // * Store a radius into a variable. +let r= 10; +console.log (r); + // * Calculate the circumference based on the radius, and log "The circumference is `circumferenceResult`". +let circumferenceResult= 2 * Math.PI * r; +console.log ("The circumference is" + circumferenceResult); + // * Calculate the area based on the radius, and log "The area is `areaOfCircle`". // * Hint: https://www.w3schools.com/jsref/jsref_pi.asp +let areaOfCircle= Math.PI * r **2; +console.log ("The area is" + areaOfCircle); + + // ## Problem Four From 1b62bb10cb0cdf560d7af5922975c849f5c41f94 Mon Sep 17 00:00:00 2001 From: Daliz Cruz Date: Wed, 9 Dec 2020 22:41:29 -0500 Subject: [PATCH 2/2] variables lab --- .DS_Store | Bin 0 -> 6148 bytes problems/variables.js | 106 ++++++++++++++++++++++++++++-------------- 2 files changed, 71 insertions(+), 35 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4c7bbea9410df65a913a9ed53334a2f0cc6093a8 GIT binary patch literal 6148 zcmeHK&2G~`5S~o~T?Zj@Kx&V^aI2~`MU{F$G9f+mfK*`w2SBZjBWlU@MzKQ#A;_-* zFTr#43HmtYo86^Km2#yOnvrI|*`1lS_uJL}5Rn>8vmK%?5osu6D?o9Bu%C5BTE3+X zRJM+|J--rElcW z^v08&XNM69CB9 zNGq`U%E&pP$H-&j5FUtfsX&*i{1ZdDbhL*)F7ntobm^r0<3sr`EB``K_Uq_BwBe*8 zhf)dy!oYO~)?BsA=l{Xq-~ZQ>q$Ugq1OF8Rsy&Q{0}RQZtt*4$vo?gDKv_7had?#i j!yd(m<)e5LY6a~f8^Fk8;}9(nxd>Pqq!0%FDFeR&f+KAR literal 0 HcmV?d00001 diff --git a/problems/variables.js b/problems/variables.js index 417614d..8d316ca 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -1,55 +1,49 @@ + // ## Problem One // Age Calculator: // * Store your birth year in a constant variable. -const myBirthYear= 1991; -console.log (myBirthYear); // * Store a future year in a variable. -let futureYear= 2020; -console.log (futureYear); // * Calculate your 2 possible ages for that year based on the stored values. // * For example, if you were born in 1988, then in 2026 you'll be either 37 or 38, depending on what month it is in 2026. // * Log them to the screen like so: "I will be either `ageMin` or `ageMax` in `futureYear`", substituting the values. -let ageMax= futureYear - myBirthYear; -let ageMin= ageMax -1; -console.log (ageMax); -console.log (ageMin); -console.log (`I will be either ${ageMax} or ${ageMin} in ${futureYear}.`); + +const birthYear= 1991 +let futureYear= 2021 +let ageMax= futureYear - birthYear +let ageMin= ageMax -1 +console.log (ageMax) +console.log (ageMin) +console.log (`I will be either ${ageMax} or ${ageMin} in ${futureYear}.`) // ## Problem Two // Snack Supply Calculator: // * Store your current age in a variable. -let myAge= 29; -console.log (myAge); // * Store a maximum age in a constant variable. -const maxAge= 50; -console.log (maxAge); // * Store an estimated snack amount per day (as a number). -let snackEstmt= 2; -console.log (snackEstmt); // * Calculate how many snacks you would eat total, from your current age until the maximum age. -let snacksAtAge= snackEstmt * 365 * (maxAge - myAge); -console.log (snacksAtAge); // * Log the result to the screen like this: "You will need `snackNumber` to last you until the age of `maxAge`". -console.log (`You will need ${snacksAtAge} to last you until the age of ${maxAge}.`); + +let myAge= 29 +const maxAge= 50 +let snackEstmt= 2 +let snacksMaxAge= snackEstmt * 365 * (maxAge - myAge) +console.log (`You will need ${snacksMaxAge} to last you until the age of ${maxAge}.`) // ## Problem Three + // Calculate properties of a circle, using the definitions: http://math2.org/math/geometry/circles.htm // * Store a radius into a variable. -let r= 10; -console.log (r); - // * Calculate the circumference based on the radius, and log "The circumference is `circumferenceResult`". -let circumferenceResult= 2 * Math.PI * r; -console.log ("The circumference is" + circumferenceResult); - // * Calculate the area based on the radius, and log "The area is `areaOfCircle`". // * Hint: https://www.w3schools.com/jsref/jsref_pi.asp -let areaOfCircle= Math.PI * r **2; -console.log ("The area is" + areaOfCircle); - +let r= 10 +let circumferenceResult= 2 * Math.PI * r +console.log ("The circumference is" +circumferenceResult) +let areaOfCircle= Math.PI * r **2 +console.log ("The area is" +areaOfCircle) // ## Problem Four @@ -58,7 +52,12 @@ console.log ("The area is" + areaOfCircle); // * Convert it to fahrenheit and output "`tempInCelsius`°C is `tempInFahrenheit`°F". // * Now store a fahrenheit temperature into a variable. // * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." - +let tempInC= 30 +let tempInF= 36 * (9/5) + 32 +console.log (`${tempInC}°C is ${tempInF}°F `) +let tempInF2 = 17 +let tempInC2 = 17 - 32 * (5/9) +console.log (`${tempInF2}°F is ${tempInC2}°C`) // ## Problem Five @@ -71,6 +70,17 @@ console.log ("The area is" + areaOfCircle); // * Find the average grade of all students // * Print out if Dee's grade is higher than the class average +let aliceGrade= 90 +let bobGrade= 80 +let camGrade= 85 +let studentAvg= (aliceGrade + bobGrade + camGrade)/3 +console.log (studentAvg) +let deeGrade= 100 +let classAvg= (deeGrade + studentAvg) / 2 +console.log (classAvg) +console.log (`Dee's grade of ${deeGrade} is higher than the class average of ${classAvg}`) + + // ## Problem Six // Find the last number: @@ -80,10 +90,11 @@ console.log ("The area is" + areaOfCircle); // * a = 123 // * Output: // * 3 - // Hint: // Use the remainder % operator. +let a= 153 % 5 +console.log (a) // ## Problem Seven @@ -109,6 +120,14 @@ console.log ("The area is" + areaOfCircle); // * alice + x = y * (bob + x) // * Solve for alice +let x = 1 +let y = 2 +let bobAge = 12 +//Alice's age equation: A+x=y*(B+x) => A= yB + yx -x +let aliceAge = y * bobAge + y * x - x +console.log(aliceAge) + + // ## Problem Eight // * Cat and Dog Percentages @@ -122,6 +141,14 @@ console.log ("The area is" + areaOfCircle); // * 25% of the daycare animals are cats // * 75% of the daycare animals are dogs +let numberOfCats = 40 +let numberOfDogs = 30 +let totalAnimals = 70 +let catPercent = Math.round ((numberOfCats / totalAnimals) * 100) +let dogPercent = Math.round ((numberOfDogs / totalAnimals) * 100) +console.log (`Percentage of cats in animal daycare is: ${catPercent}%.`) +console.log (`Percentage of dogs in animal daycare is: ${dogPercent}%.`) + // ## Problem Nine // * Leap Year Calculator @@ -133,7 +160,6 @@ console.log ("The area is" + areaOfCircle); // * Years that are divisible by 100 are not leap years if they are not also divisible by 400. // * For example 1900 was not a leap year, but 2000 was. Print "Leap year!" or "Not a leap year!" depending on the year you are provided. - // ## Problem Ten: Predict the output // For this section write what you think will be logged as a comment next to `console.log` like so: `console.log('Cat') //'Cat'` before running the code. Then execute your file and compare with your prediction. @@ -143,22 +169,32 @@ console.log ("The area is" + areaOfCircle); // let num1 = 2 // let num2 = 5 // let num3 = num1 * num2 -// console.log(num3) +// console.log(num3) // 10 // ``` +let num1 = 2 +let num2 = 5 +let num3 = num1 * num2 +console.log(num3) + // b. // ```js // let str = 'jel' // str += 'lo' -// console.log(str) +// console.log(str)// 'jello' // ``` +let str = 'jel' +str += 'lo' +console.log(str) // c. // ```js // let string = 'My favorite number is '; // let number = 42 // let sentence = string + number -// console.log(typeof(sentence)) +// console.log(typeof(sentence))// string // ``` - - +let string = 'My favorite number is '; +let number = 42 +let sentence = string + number +console.log(typeof(sentence)) \ No newline at end of file