diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..4c7bbea Binary files /dev/null and b/.DS_Store differ diff --git a/problems/variables.js b/problems/variables.js index 831a97c..8d316ca 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -1,3 +1,4 @@ + // ## Problem One // Age Calculator: @@ -7,6 +8,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= 1991 +let futureYear= 2021 +let ageMax= futureYear - birthYear +let ageMin= ageMax -1 +console.log (ageMax) +console.log (ageMin) +console.log (`I will be either ${ageMax} or ${ageMin} in ${futureYear}.`) + // ## Problem Two // Snack Supply Calculator: @@ -16,6 +25,12 @@ // * 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 myAge= 29 +const maxAge= 50 +let snackEstmt= 2 +let snacksMaxAge= snackEstmt * 365 * (maxAge - myAge) +console.log (`You will need ${snacksMaxAge} 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 +39,12 @@ // * Calculate the area based on the radius, and log "The area is `areaOfCircle`". // * Hint: https://www.w3schools.com/jsref/jsref_pi.asp +let r= 10 +let circumferenceResult= 2 * Math.PI * r +console.log ("The circumference is" +circumferenceResult) +let areaOfCircle= Math.PI * r **2 +console.log ("The area is" +areaOfCircle) + // ## Problem Four // Temperature Converter: @@ -31,7 +52,12 @@ // * 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 tempInC= 30 +let tempInF= 36 * (9/5) + 32 +console.log (`${tempInC}°C is ${tempInF}°F `) +let tempInF2 = 17 +let tempInC2 = 17 - 32 * (5/9) +console.log (`${tempInF2}°F is ${tempInC2}°C`) // ## Problem Five @@ -44,6 +70,17 @@ // * Find the average grade of all students // * Print out if Dee's grade is higher than the class average +let aliceGrade= 90 +let bobGrade= 80 +let camGrade= 85 +let studentAvg= (aliceGrade + bobGrade + camGrade)/3 +console.log (studentAvg) +let deeGrade= 100 +let classAvg= (deeGrade + studentAvg) / 2 +console.log (classAvg) +console.log (`Dee's grade of ${deeGrade} is higher than the class average of ${classAvg}`) + + // ## Problem Six // Find the last number: @@ -53,10 +90,11 @@ // * a = 123 // * Output: // * 3 - // Hint: // Use the remainder % operator. +let a= 153 % 5 +console.log (a) // ## Problem Seven @@ -82,6 +120,14 @@ // * alice + x = y * (bob + x) // * Solve for alice +let x = 1 +let y = 2 +let bobAge = 12 +//Alice's age equation: A+x=y*(B+x) => A= yB + yx -x +let aliceAge = y * bobAge + y * x - 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 = 40 +let numberOfDogs = 30 +let totalAnimals = 70 +let catPercent = Math.round ((numberOfCats / totalAnimals) * 100) +let dogPercent = Math.round ((numberOfDogs / totalAnimals) * 100) +console.log (`Percentage of cats in animal daycare is: ${catPercent}%.`) +console.log (`Percentage of dogs in animal daycare is: ${dogPercent}%.`) + // ## Problem Nine // * Leap Year Calculator @@ -106,7 +160,6 @@ // * 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. - // ## 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 +169,32 @@ // let num1 = 2 // let num2 = 5 // let num3 = num1 * num2 -// console.log(num3) +// console.log(num3) // 10 // ``` +let num1 = 2 +let num2 = 5 +let num3 = num1 * num2 +console.log(num3) + // b. // ```js // let str = 'jel' // str += 'lo' -// console.log(str) +// console.log(str)// 'jello' // ``` +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)) +// console.log(typeof(sentence))// string // ``` - - +let string = 'My favorite number is '; +let number = 42 +let sentence = string + number +console.log(typeof(sentence)) \ No newline at end of file