From 0738479c553293078c074788261702efe22bea6f Mon Sep 17 00:00:00 2001 From: Hady Mohamed Date: Tue, 8 Dec 2020 23:36:33 -0500 Subject: [PATCH 1/3] need help with questions 7,8,& 9 --- problems/variables.js | 65 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/problems/variables.js b/problems/variables.js index 831a97c..87af006 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -7,6 +7,13 @@ // * 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 = 1987 + let futureYear = 2063 + const ageMin = 75 + const ageMax = 76 + console.log("I will be either " + ageMin + " or " + ageMax + " in " + futureYear) + + // ## Problem Two // Snack Supply Calculator: @@ -16,6 +23,16 @@ // * 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 = 33 + const maxAge = 100 + let daysPerYear = 365 + let snacksPerDay = 3 + let snackNumber = (daysPerYear * (maxAge - myAge) * snacksPerDay) + //Calculation: 365 days * 67 years * 3 snacks a day = 73,365 snacks + console.log("You will need " + snackNumber + " snacks 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 @@ -24,6 +41,16 @@ // * Calculate the area based on the radius, and log "The area is `areaOfCircle`". // * Hint: https://www.w3schools.com/jsref/jsref_pi.asp +const circleRadius = 10 +const circleDiameter = 20 +// Diameter is 2 * circleRadius +const circumferenceResult = Math.PI * circleDiameter +console.log("The circumference is " + circumferenceResult) +const areaOfCircle = Math.PI * (Math.pow(circleRadius, 2)) +// Area = Pi * radius squared +console.log("The area is " + areaOfCircle) + + // ## Problem Four // Temperature Converter: @@ -32,6 +59,13 @@ // * Now store a fahrenheit temperature into a variable. // * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." +let tempInCelsius = 50 +let tempInFahrenheit = (tempInCelsius * 1.8) + 32 +console.log(tempInFahrenheit) + +let tempFahrenheit = 120 +let tempCelsius = (tempFahrenheit - 32)/1.8 +console.log(tempCelsius) // ## Problem Five @@ -44,6 +78,17 @@ // * Find the average grade of all students // * Print out if Dee's grade is higher than the class average +let alicesGrade = 97 +let bobsGrade = 100 +let camsGrade = 88 +let averageStudentGrade = (alicesGrade + bobsGrade + camsGrade)/3 +console.log("The average grade of all 3 students is " + averageStudentGrade) +let deesGrade = 100 +let newStudentAverageGrade = (alicesGrade + bobsGrade + camsGrade + deesGrade)/4 +console.log("The new average of all 4 students is " + newStudentAverageGrade) +if (newStudentAverageGrade > averageStudentGrade){ console.log("Dee's Score 96.25 ")} + + // ## Problem Six // Find the last number: @@ -57,6 +102,7 @@ // Hint: // Use the remainder % operator. +console.log(123 % 3) // ## Problem Seven @@ -116,22 +162,33 @@ // let num1 = 2 // let num2 = 5 // let num3 = num1 * num2 -// console.log(num3) +// console.log(num3) // ``` + let num1 = 2 + let num2 = 5 + let num3 = num1 * num2 + console.log(num3) //10 // b. // ```js // let str = 'jel' // str += 'lo' -// console.log(str) +// console.log(str) // ``` + let str = 'jel' + str += 'lo' + console.log(str) //jello + // c. // ```js // let string = 'My favorite number is '; // let number = 42 // let sentence = string + number -// console.log(typeof(sentence)) +// console.log(typeof(sentence)) // ``` - +let string = 'My favorite number is' +let number = 42 +let sentence = string + number +console.log(typeof(sentence)) //String From 5e3a8c4d31be12660cc8ed20501927c6e50ba250 Mon Sep 17 00:00:00 2001 From: Hady Mohamed Date: Wed, 9 Dec 2020 10:50:32 -0500 Subject: [PATCH 2/3] updated my assignment --- problems/variables.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/problems/variables.js b/problems/variables.js index 87af006..5c82968 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -128,6 +128,8 @@ console.log(123 % 3) // * alice + x = y * (bob + x) // * Solve for alice +let alice = y * (bob + x) - x + // ## Problem Eight // * Cat and Dog Percentages @@ -152,6 +154,18 @@ console.log(123 % 3) // * 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 isDivByFour = (year % 4) === 0 +let isDivBy100 = (year % 100) === 0 +let isDivBy400 = (year % 400) === 0 + +let isLeapYear = isDivByFour && (!isDivBy100 || isDivBy400) + +console.log('Year ' + year + 'is a leap year: ' + isLeapYear) + + + // ## Problem Ten: Predict the output From 77dc1f3d5082d7b30d27913f7c2b8acc1227bbfa Mon Sep 17 00:00:00 2001 From: Hady Mohamed Date: Wed, 9 Dec 2020 11:19:14 -0500 Subject: [PATCH 3/3] finish the missing questions --- problems/variables.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/problems/variables.js b/problems/variables.js index 5c82968..b48aac2 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -128,8 +128,14 @@ console.log(123 % 3) // * alice + x = y * (bob + x) // * Solve for alice +let x = 3 +let y = 2 +let bob = 12 + let alice = y * (bob + x) - x +console.log(alice) + // ## Problem Eight // * Cat and Dog Percentages @@ -143,6 +149,13 @@ let alice = y * (bob + x) - x // * 25% of the daycare animals are cats // * 75% of the daycare animals are dogs +let numberOfCats = 20 +let numberOfDogs = 60 +let totalNumberOfAnimals = numberOfCats + numberOfDogs +let percentageOfCats = Math.round((numberOfCats/totalNumberOfAnimals)*100) + +console.log(percentageOfCats + "% of the daycare animals are cats ") + // ## Problem Nine // * Leap Year Calculator