From 7c950af69b3545c4e99dadb3d77d845249258b98 Mon Sep 17 00:00:00 2001 From: Sarah Weinstein Date: Tue, 8 Dec 2020 22:43:26 -0500 Subject: [PATCH 1/3] Variables Lab --- problems/variables.js | 96 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/problems/variables.js b/problems/variables.js index 831a97c..033fcec 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -7,6 +7,17 @@ // * 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. +const birthYear = 1988; +let futureYear = 2021; +let ageMin = 32; +let ageMax = 33; +let string = "I will be either "; +let string2 = " or "; +let string3 = " in "; +let sentence = string + ageMin + string2 + ageMax + string3 + futureYear; +console.log(sentence); +//I will be either 32 or 33 in 2021 + // ## Problem Two // Snack Supply Calculator: @@ -16,6 +27,21 @@ // * Calculate how many snacks you would eat total, from your current age until the maximum age. // * Log the result to the screen like this: "You will need `snackNumber` to last you until the age of `maxAge`". +let myAge = 32; +const maxAge = 100; +let numPerDay = 2; +let totalNeeded = (numPerDay * 365) * (maxAge - myAge); +console.log(totalNeeded); +// 49640 + +let snackNumber = 49640; +let string = "You will need "; +let string2 = " snacks to last you until the age of "; +let sentence = string + snackNumber + string2 + maxAge; +console.log(sentence); +//You will need 49640 snacks to last you until the age of 100 + + // ## Problem Three // Calculate properties of a circle, using the definitions: http://math2.org/math/geometry/circles.htm @@ -24,6 +50,15 @@ // * Calculate the area based on the radius, and log "The area is `areaOfCircle`". // * Hint: https://www.w3schools.com/jsref/jsref_pi.asp +let radius = 3; +let circumference = Math.PI * 2*radius; +console.log = ("The circumference is " + circumference); +//The circumference is 18.84955592153876 + +let area = Math.PI * radius * radius; +console.log("The area is " + area); +//The area is 28.274333882308138 + // ## Problem Four // Temperature Converter: @@ -32,6 +67,22 @@ // * Now store a fahrenheit temperature into a variable. // * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." +let tempInCelsius = 30; +let tempInFahrenheit = (tempInCelsius * 9)/5 + 32; +let string1 = "°C is "; +let string2 = "°F."; +let sentence = tempInCelsius + string1 + tempInFahrenheit + string2; +console.log(sentence); +//30°C is 86°F. + +let tempInFahrenheit = 20; +let tempInCelsius = ((tempInFahrenheit-32)*5)/9; +let string1 = "°F is "; +let string2 = "°C."; +let message = tempInFahrenheit + string1 + tempInCelsius + string2; +console.log(message); +// 20°F is -6.666666666666667°C. + // ## Problem Five @@ -44,6 +95,23 @@ // * Find the average grade of all students // * Print out if Dee's grade is higher than the class average +let aliceGrade = 70; +let bobGrade = 80; +let camGrade = 85; +let averageGrade = (aliceGrade+bobGrade+camGrade)/3; +console.log(averageGrade); +// 78.33333333333333 + +let deeGrade = 90; +let allAverage = (averageGrade + deeGrade)/2; +console.log (allAverage); +// 84.16666666666666 + +let message = ("Dee's grade is higher than the class average"); +console.log(message);git +// Dee's grade is higher than the class average + + // ## Problem Six // Find the last number: @@ -57,6 +125,12 @@ // Hint: // Use the remainder % operator. +let a = 12345678; +let a = 12345678; +lastNumber = a % 10; +console.log(lastNumber); +//8 + // ## Problem Seven @@ -95,6 +169,12 @@ // * 25% of the daycare animals are cats // * 75% of the daycare animals are dogs +let numberOfCats = 20 +let numberOfDogs = 60 + + + + // ## Problem Nine // * Leap Year Calculator @@ -107,6 +187,8 @@ // * 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. @@ -117,7 +199,11 @@ // let num2 = 5 // let num3 = num1 * num2 // console.log(num3) -// ``` +// ``` + +```js +// 10 +``` // b. // ```js @@ -126,6 +212,10 @@ // console.log(str) // ``` +```js +// jello +``` + // c. // ```js // let string = 'My favorite number is '; @@ -134,4 +224,8 @@ // console.log(typeof(sentence)) // ``` +```js +// String +``` + From b2053b9e34a776a1176195443c1d606afef00ab3 Mon Sep 17 00:00:00 2001 From: Sarah Weinstein Date: Thu, 10 Dec 2020 18:42:20 -0500 Subject: [PATCH 2/3] Updated Variables Lab --- .DS_Store | Bin 0 -> 6148 bytes problems/variables.js | 72 +++++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 33 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..31930c40d63a7f006d80f72b8ae03aa2e07cd5ff GIT binary patch literal 6148 zcmeH~Jx;?w5QX1B3L~17lzW0m+`vRmk%ER?0GS{f6GuT%`$jn;y!in+!gYkujI{g4 zyE9|^lf3H%Aj|jdEieaAv8jqW6Q;wHQx_3@NfoQn;Tf-ZTX+4_M4`Vpq|aVqj{|zN z7(IX6^)2TV%pKd}(~RCk{Kw|7>-yab=g0w9c)*HT4eqH664@$|QN<&p#ua&)mIRVO z5=a6`;7kN`ucB4guGuGnB#;Dt2NdO9Qy9};)|KD>zCo%M@_Lu%LTlRy$UC7@?t+FbYl6+fBD zL%xM%mjsf)e@`n#K+4(CDB11n@%FksF)z`Jz7K>d?Ve TtLV6;Q}ai_fMk~h&OqP`fbA|K literal 0 HcmV?d00001 diff --git a/problems/variables.js b/problems/variables.js index 033fcec..e4b2c15 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -8,15 +8,15 @@ // * Log them to the screen like so: "I will be either `ageMin` or `ageMax` in `futureYear`", substituting the values. const birthYear = 1988; -let futureYear = 2021; -let ageMin = 32; -let ageMax = 33; +let futureYear = 2024; +let ageMin = 35; +let ageMax = 36; let string = "I will be either "; let string2 = " or "; let string3 = " in "; -let sentence = string + ageMin + string2 + ageMax + string3 + futureYear; +let sentence = string + ageMin + string2 + ageMax + string3 + futureYear + "."; console.log(sentence); -//I will be either 32 or 33 in 2021 +// I will be either 35 or 36 in 2024. // ## Problem Two @@ -29,17 +29,17 @@ console.log(sentence); let myAge = 32; const maxAge = 100; -let numPerDay = 2; -let totalNeeded = (numPerDay * 365) * (maxAge - myAge); +let snacksPerDay = 2; +let totalNeeded = (maxAge - myAge) * (snacksPerDay * 365); console.log(totalNeeded); // 49640 let snackNumber = 49640; let string = "You will need "; let string2 = " snacks to last you until the age of "; -let sentence = string + snackNumber + string2 + maxAge; +let sentence = string + snackNumber + string2 + maxAge + "."; console.log(sentence); -//You will need 49640 snacks to last you until the age of 100 +// You will need 49640 snacks to last you until the age of 100. // ## Problem Three @@ -52,12 +52,12 @@ console.log(sentence); let radius = 3; let circumference = Math.PI * 2*radius; -console.log = ("The circumference is " + circumference); -//The circumference is 18.84955592153876 +console.log = ("The circumference is " + circumference + "."); +// The circumference is 18.84955592153876. let area = Math.PI * radius * radius; -console.log("The area is " + area); -//The area is 28.274333882308138 +console.log = ("The area is " + area + "."); +// The area is 28.274333882308138. // ## Problem Four @@ -73,7 +73,7 @@ let string1 = "°C is "; let string2 = "°F."; let sentence = tempInCelsius + string1 + tempInFahrenheit + string2; console.log(sentence); -//30°C is 86°F. +// 30°C is 86°F. let tempInFahrenheit = 20; let tempInCelsius = ((tempInFahrenheit-32)*5)/9; @@ -83,7 +83,6 @@ let message = tempInFahrenheit + string1 + tempInCelsius + string2; console.log(message); // 20°F is -6.666666666666667°C. - // ## Problem Five // Grades Calculator: @@ -98,19 +97,18 @@ console.log(message); let aliceGrade = 70; let bobGrade = 80; let camGrade = 85; -let averageGrade = (aliceGrade+bobGrade+camGrade)/3; +let averageGrade = (aliceGrade + bobGrade + camGrade) / 3; console.log(averageGrade); // 78.33333333333333 let deeGrade = 90; -let allAverage = (averageGrade + deeGrade)/2; -console.log (allAverage); +let avg = (averageGrade + deeGrade)/2; +console.log (avg); // 84.16666666666666 -let message = ("Dee's grade is higher than the class average"); -console.log(message);git -// Dee's grade is higher than the class average - +let isDeeGradeAboveAvg = deeGrade > avg +console.log('Dee\'s grade is higher than the average: ' + isDeeGradeAboveAvg) +// Dee's grade is higher than the average: true // ## Problem Six @@ -125,12 +123,10 @@ console.log(message);git // Hint: // Use the remainder % operator. -let a = 12345678; let a = 12345678; lastNumber = a % 10; console.log(lastNumber); -//8 - +// 8 // ## Problem Seven @@ -156,6 +152,13 @@ console.log(lastNumber); // * alice + x = y * (bob + x) // * Solve for alice +let x = 1 +let y = 3 +let bob = 12 +let alice = y * (bob + x) - 1 +console.log (alice) +// 38 + // ## Problem Eight // * Cat and Dog Percentages @@ -169,11 +172,10 @@ console.log(lastNumber); // * 25% of the daycare animals are cats // * 75% of the daycare animals are dogs -let numberOfCats = 20 -let numberOfDogs = 60 - - - +let numberOfCats = (20/80 * 100) + "% " +let numberOfDogs = (60/80 * 100) + "% " +console.log("The percentage of dogs in daycare is " + (numberOfDogs) + "and the percentage of cats in the class is " + (numberOfCats) + ".") +// The percentage of dogs in daycare is 75% and the percentage of cats in the class is 25% . // ## Problem Nine @@ -186,8 +188,14 @@ let numberOfDogs = 60 // * 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. +let year = 2020 +let isDivBy4 = (year % 4) +let isDivBy100 = (year % 100) +let isDivBy400 = (year % 400) +let isLeapYear = isDivBy4 && (!isDivBy100 || isDivBy400) +console.log ('Year ' + year + ' is a leap year! ' + isLeapYear) // ## Problem Ten: Predict the output @@ -226,6 +234,4 @@ let numberOfDogs = 60 ```js // String -``` - - +``` \ No newline at end of file From 7d4978f3962a6bf5f3cb99d0d9798e41726ed31b Mon Sep 17 00:00:00 2001 From: Sarah Weinstein Date: Thu, 10 Dec 2020 18:49:16 -0500 Subject: [PATCH 3/3] Updated Lab Entry --- problems/variables.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/variables.js b/problems/variables.js index e4b2c15..dd10935 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -194,8 +194,8 @@ let isDivBy100 = (year % 100) let isDivBy400 = (year % 400) let isLeapYear = isDivBy4 && (!isDivBy100 || isDivBy400) - console.log ('Year ' + year + ' is a leap year! ' + isLeapYear) +// Year 2020 is a leap year! 0 // ## Problem Ten: Predict the output