diff --git a/problems/variables.js b/problems/variables.js index 831a97c..1c14bce 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -6,15 +6,29 @@ // * 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. +//question 1 +const birthYear = 1965 +let futureYear = 2022 +let ageMin = 2022 - birthYear - 1 +let ageMax = 2022 - birthYear +console.log('In ' + futureYear + ' I will either be ' + ageMin + ' or ' + ageMax ) + + // ## Problem Two + // Snack Supply Calculator: // * Store your current age in a variable. // * Store a maximum age in a constant variable. // * Store an estimated snack amount per day (as a number). // * 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 = 54 +const maxAge = 200 +let snackNumber = 2 +let yearsGoneBy = maxAge - currentAge +console.log('I will need ' + snackNumber * yearsGoneBy + ' snacks to last until the age of ' + yearsGoneBy) // ## Problem Three @@ -23,6 +37,11 @@ // * Calculate the circumference based on the radius, and 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 radius = 2 +let circumferenceResult = (Math.PI*2) * radius +console.log('The circumference is ' + circumferenceResult) +let area = Math.PI * (radius**2) +console.log('The area is ' + area) // ## Problem Four @@ -31,7 +50,9 @@ // * 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 tempInCelsius = 0 +let tempInFahrenheit = 32 +console.log(tempInFahrenheit + "°F is " + tempInCelsius + "°C") // ## Problem Five @@ -43,6 +64,15 @@ // * Store Dee's grade on a test to a variable // * Find the average grade of all students // * Print out if Dee's grade is higher than the class average +let aliceGrade = 20 +let bobGrade = 75 +let camGrade = 100 +let threeStudents = aliceGrade + bobGrade + camGrade +let avg1 = threeStudents / 3 +let deesGrade = 100 +let fourStudents = threeStudents + deesGrade +let avg2 = fourStudents / 4 +console.log("Dee's grade of " + deesGrade + "% is higher the the class average of " + avg2 + "%") // ## Problem Six @@ -53,7 +83,9 @@ // * a = 123 // * Output: // * 3 - +let a = 5002 +let output = a % 5000 +console.log(output) // Hint: // Use the remainder % operator. @@ -77,7 +109,11 @@ // * bob = 12 // * Expected values: // * alice = 38 - +let x = 3; +let y = 2; +const bob = 12; +let aliceAge = y * ( bob + x) - x; +console.log(aliceAge); // * Hint: // * alice + x = y * (bob + x) // * Solve for alice @@ -95,6 +131,14 @@ // * 25% of the daycare animals are cats // * 75% of the daycare animals are dogs +let dogs = 20 +let cats = 60 +let total = dogs + cats +numberOfCats = cats/total * 100 +numberOfDogs = dogs/total * 100 +console.log(numberOfCats + "%" + " of the daycare animals are cats") +console.log(numberOfDogs + "%" + " of the daycare animals are dogs") + // ## Problem Nine // * Leap Year Calculator @@ -110,28 +154,9 @@ // ## 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. - -// a. -// ```js -// let num1 = 2 -// let num2 = 5 -// let num3 = num1 * num2 -// console.log(num3) -// ``` - -// b. -// ```js -// 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)) -// ``` - - +/a +console.log(10) +//b +console.log('jello') +//c +console.log(typeof'My favorite number is 42')