From 985f523aef87d477f81f4f3e37d265e672fb2174 Mon Sep 17 00:00:00 2001 From: Jasleen Villamil Date: Wed, 9 Dec 2020 09:36:20 -0500 Subject: [PATCH 1/2] Questions 1- 8 out of 10 attempted in Variables Assignment --- problems/variables.js | 95 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/problems/variables.js b/problems/variables.js index 831a97c..9d9f779 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -1,9 +1,32 @@ // ## Problem One // Age Calculator: -// * Store your birth year in a constant variable. +// * Store your birth year in a constant variable. +const birthYear = 1994 +console.log(birthYear) + // * Store a future year in a variable. +let futureYear = 2090 +console.log(futureYear) + // * Calculate your 2 possible ages for that year based on the stored values. +let ageMax= (futureYear - birthYear) +console.log(ageMax) + +let ageMin= (ageMax - 1) +console.log(ageMin) + +let sentence1 = `I will be either ` +let sentence2 = ' or ' +let sentence3 = ' or ' +sentence = `I will be either ` + ageMin + ' or '+ ageMax + ' or '+ futureYear +console.log(sentence) + +let sentence4= "I will be either " + ageMin +` or `+ ageMax +` in `+futureYear +console.log(sentence4) + // + + // * 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. @@ -11,25 +34,58 @@ // Snack Supply Calculator: // * Store your current age in a variable. + +const currentAge = 26 +console.log(currentAge) + // * Store a maximum age in a constant variable. + +const maxAge = 100 +console.log(maxAge) + // * Store an estimated snack amount per day (as a number). +let estimatedSnacks = 4 +console.log(estimatedSnacks) + // * Calculate how many snacks you would eat total, from your current age until the maximum age. +let days = (maxAge - currentAge) * 365 +let snackNumber = days * 4 +console.log(snackNumber) + +let sentence5= "You will need " + snackNumber + " snacks to last you until the age of " + maxAge +console.log(sentence5) // * Log the result to the screen like this: "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 // * Store a radius into a variable. + +let radius = 4 + // * Calculate the circumference based on the radius, and log "The circumference is `circumferenceResult`". +let circumference = 2 * 3.14 * radius + // * Calculate the area based on the radius, and log "The area is `areaOfCircle`". // * Hint: https://www.w3schools.com/jsref/jsref_pi.asp +let areaOfCircle = 3.14 * (radius**2) +console.log ( areaOfCircle, circumference) + + + // ## Problem Four // Temperature Converter: // * Store a celsius temperature into a variable. +let celsius = 32 // * Convert it to fahrenheit and output "`tempInCelsius`°C is `tempInFahrenheit`°F". +let tempInFahrenheit = (celsius * 9/5) + 32 +console.log( ) + // * Now store a fahrenheit temperature into a variable. + + // * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." @@ -37,17 +93,39 @@ // Grades Calculator: // * Store Alices's grade on a test to a variable +let alicesGrade = 90 + + // * Store Bob's grade on a test to a variable +let bobsGrade = 65 + // * Store Cam's grade on a test to a variable +let camsGrade = 80 // * Find the average grade of all students +let averageGrade = (bobsGrade + alicesGrade + camsGrade)/3 +console.log(averageGrade) + // * Store Dee's grade on a test to a variable +let deesGrade= 100 + // * Find the average grade of all students +let averageTest = (bobsGrade + alicesGrade + camsGrade + deesGrade)/4 +console.log(averageTest) + // * Print out if Dee's grade is higher than the class average +let testSentence = "Dee's grade is " + deesGrade + " higher than the class average" ++ averageTest + +console.log (testSentence) + // ## Problem Six // Find the last number: // * You are given a number a. Print the last digit of a. +let a = 122 +console.log(a%10) + // * Example // * Input: // * a = 123 @@ -82,6 +160,14 @@ // * alice + x = y * (bob + x) // * Solve for alice + +let bob = 12 +let x = 5 +let y = 2 +let alice = y * (bob +x)-x +console.log(alice) + + // ## Problem Eight // * Cat and Dog Percentages @@ -94,6 +180,13 @@ // * Output: // * 25% of the daycare animals are cats // * 75% of the daycare animals are dogs +let numberOfCats = 40 +let numberOfDogs = 25 +let daycare = 65 +let percentageOfCats = (numberOfCats * 100) /65 +let percentageOfDogs = (numberOfDogs *100)/65 +console.log( percentageOfCats, percentageOfDogs) + // ## Problem Nine From 422c2f5e34b53971cf4e6934b3b45adb01237b20 Mon Sep 17 00:00:00 2001 From: Jasleen Villamil Date: Fri, 1 Jan 2021 19:03:32 -0500 Subject: [PATCH 2/2] Corrected some sentences, and finished all unsolved problems. --- problems/variables.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/problems/variables.js b/problems/variables.js index 9d9f779..c46a693 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -70,7 +70,7 @@ let circumference = 2 * 3.14 * radius // * Hint: https://www.w3schools.com/jsref/jsref_pi.asp let areaOfCircle = 3.14 * (radius**2) -console.log ( areaOfCircle, circumference) +console.log ("The area is " + areaOfCircle + " The circumference is " + circumference) @@ -81,13 +81,15 @@ console.log ( areaOfCircle, circumference) let celsius = 32 // * Convert it to fahrenheit and output "`tempInCelsius`°C is `tempInFahrenheit`°F". let tempInFahrenheit = (celsius * 9/5) + 32 -console.log( ) +console.log ('The temp ' + celsius + ' degrees in celsius is ' + tempInFahrenheit + ' degrees in fahrenheit') // * Now store a fahrenheit temperature into a variable. +let fahrenheit = 89 // * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." - +tempInCelsius = (fahrenheit - 32) * 5/9 +console.log('The temp ' + fahrenheit+ ' degrees in fahrenehit is ' + tempInCelsius+ ' degrees in celsius') // ## Problem Five @@ -113,7 +115,7 @@ let averageTest = (bobsGrade + alicesGrade + camsGrade + deesGrade)/4 console.log(averageTest) // * Print out if Dee's grade is higher than the class average -let testSentence = "Dee's grade is " + deesGrade + " higher than the class average" +let testSentence = "Dee's grade of " + deesGrade + " is higher than the class average " + averageTest console.log (testSentence) @@ -199,6 +201,15 @@ console.log( percentageOfCats, percentageOfDogs) // * 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. +function leapYear(year) +{ + return (year % 100 === 0) ? (year % 400 === 0): (year % 4 ===0) + +} +console.log(leapYear(1900)) +console.log(leapYear(1731)) +console.log(leapYear(2012)) + // ## Problem Ten: Predict the output @@ -209,14 +220,14 @@ console.log( percentageOfCats, percentageOfDogs) // let num1 = 2 // let num2 = 5 // let num3 = num1 * num2 -// console.log(num3) +// console.log(num3) = 10 // ``` // b. // ```js // let str = 'jel' // str += 'lo' -// console.log(str) +// console.log(str) = jello // ``` // c. @@ -224,7 +235,7 @@ console.log( percentageOfCats, percentageOfDogs) // let string = 'My favorite number is '; // let number = 42 // let sentence = string + number -// console.log(typeof(sentence)) +// console.log(typeof(sentence)) = string // ```