diff --git a/problems/variables.js b/problems/variables.js index 831a97c..117414f 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -7,6 +7,14 @@ // * 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 = 1990 + let futureYear = 2026 + let ageMax = futureYear - birthYear + let ageMin = ageMax - 1 + + console.log(`I will be either ${ageMin} or ${ageMax} in ${futureYear}.`) + + // ## Problem Two // Snack Supply Calculator: @@ -16,14 +24,27 @@ // * 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`". -// ## Problem Three +let curAge = "30" +const maxAge = "99" +let snackCount = "3" +let snackNumber = ((maxAge - curAge)*(snackCount * 365)) + +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 // * Store a radius into a variable. // * 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 = 7 +let areaOfCircle = (radius * radius * Math.PI) +let circumferenceOfCircle = (Math.PI * radius * 2) +console.log(`The circumference is ${circumferenceOfCircle} and the area is ${areaOfCircle}.`) // ## Problem Four // Temperature Converter: @@ -32,6 +53,14 @@ // * Now store a fahrenheit temperature into a variable. // * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." +let celsius = 23 +let cToF = (celsius * 1.8 + 32) +let fahrenheit = 56 +let fToC = ((fahrenheit - 32) / 1.8) + +console.log(`${celsius}° C is ${cToF}° F`); +console.log(`${fahrenheit}°F is ${fToC}°C`) + // ## Problem Five @@ -44,6 +73,16 @@ // * Find the average grade of all students // * Print out if Dee's grade is higher than the class average +let alice = 70 +let bob = 50 +let cam = 30 +let average = ((bob + cam + alice) / 3) +let dee = 90 +average = ((bob + cam + alice + dee) / 4) + +if(dee > average ) console.log(`Dees grade is higher than average`) + + // ## Problem Six // Find the last number: @@ -53,6 +92,11 @@ // * a = 123 // * Output: // * 3 + +let a = 6790 +let output = a % 10 + +console.log(`The last digit of ${a} is ${output}.`) // Hint: // Use the remainder % operator. @@ -82,6 +126,13 @@ // * alice + x = y * (bob + x) // * Solve for alice +let x = 2; +let y = 4; +let bobA = 12 +let aliceA = y * (x + bobA)- x +console.log(aliceA) + + // ## Problem Eight // * Cat and Dog Percentages @@ -95,6 +146,15 @@ // * 25% of the daycare animals are cats // * 75% of the daycare animals are dogs +let numberOfCats = 20 +let numberOfDogs = 60 + +let catPerc = ((numberOfCats / (numberOfCats + numberOfDogs))*100) +let dogPerc = ((numberOfDogs / (numberOfCats + numberOfDogs))*100) + +console.log(`The percentage of dogs in the daycare is ${dogPerc}% and the percentage of cats is ${catPerc}%.`) + + // ## Problem Nine // * Leap Year Calculator @@ -107,6 +167,20 @@ // * 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(yr) { +if ((yr % 4 == 0 ) && ( yr % 100 != 0)) +{ + console.log("Leap year!")} +else if (yr % 400 == 0) + { + console.log("Leap year!") + } +else +{ + console.log("Not a leap year!") + } +} +console.log(leapYear(2000)) // ## 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,14 +190,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 +205,5 @@ // let string = 'My favorite number is '; // let number = 42 // let sentence = string + number -// console.log(typeof(sentence)) +// console.log(typeof(sentence))/string // ``` - -