From d22fc7c960c4c861d153e590a7b2e3c5acff8075 Mon Sep 17 00:00:00 2001 From: Kelvin Zheng Date: Tue, 8 Dec 2020 17:58:34 -0500 Subject: [PATCH 1/3] solved the problems --- problems/variables.js | 68 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/problems/variables.js b/problems/variables.js index 831a97c..53bf6fa 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 = 1997 +let futureYear = 2034 +let ageMin = futureYear - birthyear +let ageMax = ageMin + 1 +console.log("I will be either " + ageMin + " or " + ageMax + " in " + futureYear) + + // ## Problem Two // Snack Supply Calculator: @@ -16,6 +23,11 @@ // * 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 currentAge = 23 +let maxAge = 55 +let snack = 2 +let snackNumber = (maxAge - currentAge) * 365 * snack +console.log ('You will need ' + snackNumber + ' 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 +36,11 @@ // * Calculate the area based on the radius, and log "The area is `areaOfCircle`". // * Hint: https://www.w3schools.com/jsref/jsref_pi.asp +let radius = 100 +let circumferenceResult = 2 * Math.PI * radius +let areaOfCircle = Math.PI * radius ** 2 + console.log ("The circumference is " + circumferenceResult + " and the circle area is " + areaOfCircle) + // ## Problem Four // Temperature Converter: @@ -32,7 +49,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 = 1.8 * tempInCelsius + 32 +console.log (tempInCelsius + ' °C is ' + tempInFahrenheit + ' °F') +let tempInFahrenheit1 = 1 +let tempInCelsius1 = (tempInFahrenheit1 - 32) * (5/9) +console.log (tempInFahrenheit1 + ' °F is ' + tempInCelsius1 + ' °C') // ## Problem Five // Grades Calculator: @@ -44,6 +67,18 @@ // * Find the average grade of all students // * Print out if Dee's grade is higher than the class average +let aliceGrade = 45 +let bobGrade = 78 +let camGrade = 100 +let currentAvg = ((aliceGrade + bobGrade + camGrade)/3) +let deeGrade = 100 +let averageWithDee = ((aliceGrade + bobGrade + camGrade + deeGrade)/4) +console.log(deeGrade > averageWithDee) + + + + + // ## Problem Six // Find the last number: @@ -57,6 +92,10 @@ // Hint: // Use the remainder % operator. +let a = 123 +let lastDigit = a % 10 +console.log (lastDigit) + // ## Problem Seven @@ -82,6 +121,13 @@ // * alice + x = y * (bob + x) // * Solve for alice +let bobAge = 12 +let x = 3 +let y = 2 +let aliceAge = y * bobAge + (y - 1) * x +console.log (aliceAge) + + // ## Problem Eight // * Cat and Dog Percentages @@ -95,6 +141,14 @@ // * 25% of the daycare animals are cats // * 75% of the daycare animals are dogs +let numberOfCats = 20 +let numberOfDogs = 60 +let percentOfCats = (numberOfCats / (numberOfCats + numberOfDogs)) +let percentOfDogs = (numberOfDogs / (numberOfCats + numberOfDogs)) +let roundPercentOfDogs = Math.floor(percentOfDogs) +let roundpercentOfCats = Math.floor(percentOfCats) +console.log(roundPercentOfDogs + " of of the daycare animals are dogs") +console.log(roundPercentOfCats + " of of the daycare animals are cats") // ## Problem Nine // * Leap Year Calculator @@ -106,7 +160,9 @@ // * 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 leapYear = 2020 +let isLeapyear = leapYear % 4 && (leapYear % 100 && leapYear % 400) +console.log((isLeapYear === 0 && "Leap year!") || isLeapYear !== 0 && 'Not a leap year!') // ## 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. @@ -116,22 +172,24 @@ // let num1 = 2 // let num2 = 5 // let num3 = num1 * num2 -// console.log(num3) +// console.log(num3) // 10 // ``` +// '10' // b. // ```js // let str = 'jel' // str += 'lo' -// console.log(str) -// ``` +// console.log(str) // jello + +// `jello' // c. // ```js // let string = 'My favorite number is '; // let number = 42 // let sentence = string + number -// console.log(typeof(sentence)) +// console.log(typeof(sentence)) //string // ``` From 772b5095b08b6ee5ad39d25b888560159be1b96d Mon Sep 17 00:00:00 2001 From: Kelvin Zheng Date: Sun, 20 Dec 2020 13:21:48 -0500 Subject: [PATCH 2/3] i have completed the assignment prior. The npm test is not working --- package-lock.json | 6 ++++++ package.json | 1 + problems/variables.js | 10 +++++----- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 package-lock.json create mode 100644 package.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f6abecc --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "variable_assignment", + "lockfileVersion": 2, + "requires": true, + "packages": {} +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/package.json @@ -0,0 +1 @@ +{} diff --git a/problems/variables.js b/problems/variables.js index 53bf6fa..b5edfcc 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -38,8 +38,8 @@ console.log ('You will need ' + snackNumber + ' to last you until the age of ' + let radius = 100 let circumferenceResult = 2 * Math.PI * radius -let areaOfCircle = Math.PI * radius ** 2 - console.log ("The circumference is " + circumferenceResult + " and the circle area is " + areaOfCircle) +let areaOfCircle = Math.PI * (radius ** 2) +console.log ("The circumference is " + circumferenceResult + " and the circle area is " + areaOfCircle) // ## Problem Four @@ -73,7 +73,7 @@ let camGrade = 100 let currentAvg = ((aliceGrade + bobGrade + camGrade)/3) let deeGrade = 100 let averageWithDee = ((aliceGrade + bobGrade + camGrade + deeGrade)/4) -console.log(deeGrade > averageWithDee) +console.log("Dee grade is higher than class average: " + deeGrade > averageWithDee) @@ -161,8 +161,8 @@ console.log(roundPercentOfCats + " of of the daycare animals are cats") // * 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 leapYear = 2020 -let isLeapyear = leapYear % 4 && (leapYear % 100 && leapYear % 400) -console.log((isLeapYear === 0 && "Leap year!") || isLeapYear !== 0 && 'Not a leap year!') +let isLeapyear = (leapYear % 4 === 0) && (leapYear % 100 !== 0 || leapYear % 400 === 0) +console.log(((isLeapYear) && "Leap year!") && ((isLeapYear) || 'Not a leap year!') // ## 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. From 9d49cf307e3169acf6f09df5dda0b23ffe600fa3 Mon Sep 17 00:00:00 2001 From: Kelvin Zheng Date: Tue, 22 Dec 2020 12:15:24 -0500 Subject: [PATCH 3/3] completed the assessment --- problems/variables.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/problems/variables.js b/problems/variables.js index b5edfcc..42420ea 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -190,6 +190,4 @@ console.log(((isLeapYear) && "Leap year!") && ((isLeapYear) || 'Not a leap year! // let number = 42 // let sentence = string + number // console.log(typeof(sentence)) //string -// ``` - - +// `` \ No newline at end of file