diff --git a/problems/variables.js b/problems/variables.js index 831a97c..c46a693 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,43 +34,100 @@ // 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 ("The area is " + areaOfCircle + " The circumference is " + 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 ('The temp ' + celsius + ' degrees in celsius is ' + tempInFahrenheit + ' degrees in fahrenheit') + // * Now store a fahrenheit temperature into a variable. -// * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." +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 // 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 of " + deesGrade + " is 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 +162,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 +182,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 @@ -106,6 +201,15 @@ // * 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 @@ -116,14 +220,14 @@ // 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. @@ -131,7 +235,7 @@ // let string = 'My favorite number is '; // let number = 42 // let sentence = string + number -// console.log(typeof(sentence)) +// console.log(typeof(sentence)) = string // ```