From 4fc3ad16a96f1c761cd7841bf8bd53b315471ab0 Mon Sep 17 00:00:00 2001 From: Coreen Cooper Date: Sun, 6 Dec 2020 23:04:08 -0500 Subject: [PATCH 01/11] add test --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index da44c2c..eb47104 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Pursuit Logo](https://avatars1.githubusercontent.com/u/5825944?s=200&v=4)](https://pursuit.org) - +test # Variables Lab Practice working with variables. @@ -22,4 +22,4 @@ Practice working with variables. ## Instructions - You should answer all your problems in the `variables.js` file. - To run the file type `node problems/variables.js` into your console. - - You can comment out code by writing `//` at the beginning of a line. Pro tip: Use Cmd + / while anywhere on a line to comment it out. \ No newline at end of file + - You can comment out code by writing `//` at the beginning of a line. Pro tip: Use Cmd + / while anywhere on a line to comment it out. \ No newline at end of file From e2382a32a1244d3969cdbc97333b996bfc41f5a5 Mon Sep 17 00:00:00 2001 From: Coreen Cooper Date: Sun, 6 Dec 2020 23:11:46 -0500 Subject: [PATCH 02/11] Revert "add test" This reverts commit 4fc3ad16a96f1c761cd7841bf8bd53b315471ab0. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eb47104..da44c2c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Pursuit Logo](https://avatars1.githubusercontent.com/u/5825944?s=200&v=4)](https://pursuit.org) -test + # Variables Lab Practice working with variables. @@ -22,4 +22,4 @@ Practice working with variables. ## Instructions - You should answer all your problems in the `variables.js` file. - To run the file type `node problems/variables.js` into your console. - - You can comment out code by writing `//` at the beginning of a line. Pro tip: Use Cmd + / while anywhere on a line to comment it out. \ No newline at end of file + - You can comment out code by writing `//` at the beginning of a line. Pro tip: Use Cmd + / while anywhere on a line to comment it out. \ No newline at end of file From ae807f95c373d0be19c77dc4bf337b6a51c3e3a4 Mon Sep 17 00:00:00 2001 From: Coreen Cooper Date: Mon, 7 Dec 2020 23:08:24 -0500 Subject: [PATCH 03/11] solve problems 1 - 3 --- problems/variables.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/problems/variables.js b/problems/variables.js index 831a97c..7ad501c 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -2,32 +2,60 @@ // Age Calculator: // * Store your birth year in a constant variable. +//const birthYear = 1975 +//console.log(birthYear) // * Store a future year in a variable. +//let futureYear = 2020 // * 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. + +//console.log(futureYear - birthYear) // * Log them to the screen like so: "I will be either `ageMin` or `ageMax` in `futureYear`", substituting the values. +//let ageMax = (futureYear - birthYear) +//console.log(ageMax) +//let ageMin = ageMax - 1 +//console.log(ageMin) +//console.log("I will be either" + " " + ageMin + " " + "or" + " " + ageMax + " " + "in" + " " + futureYear) // ## Problem Two - // Snack Supply Calculator: // * Store your current age in a variable. +// let currentAge = 45 // * Store a maximum age in a constant variable. +// const maxAge = 45 // * Store an estimated snack amount per day (as a number). +// let snack = 1 // * Calculate how many snacks you would eat total, from your current age until the maximum age. +// let snackNumber = ((currentAge-maxAge) * snack * 365) + // * Log the result to the screen like this: "You will need `snackNumber` to last you until the age of `maxAge`". +// console.log("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 = 6 + // * Calculate the circumference based on the radius, and log "The circumference is `circumferenceResult`". +// circumference = 2PI * radius +// console.log(Math.PI) +// console.log((2 * Math.PI) * radius) +// let circumferenceResult = ((2 * 3.141592653589793) * radius) +// console.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 -// ## Problem Four +// area=PI r**2 +// let areaOfCircle = (3.141592653589793) * (radius**2) +// console.log("The area is" + " " + areaOfCircle) + +// ## Problem Four // Temperature Converter: // * Store a celsius temperature into a variable. + // * 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." From bc43b9f71c2d12ae2edc3a51ab71f27108612aea Mon Sep 17 00:00:00 2001 From: Coreen Cooper Date: Tue, 8 Dec 2020 00:01:57 -0500 Subject: [PATCH 04/11] solve problem 4 --- problems/variables.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/problems/variables.js b/problems/variables.js index 7ad501c..7495c4e 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -55,16 +55,26 @@ // ## Problem Four // Temperature Converter: // * Store a celsius temperature into a variable. +// let tempInCelsius = 1 // * Convert it to fahrenheit and output "`tempInCelsius`°C is `tempInFahrenheit`°F". +// (celsius * (9/5)+32)=fahrenheit +// let tempInFahrenheit = (tempInCelsius * (9/5) + 32) +// console.log(tempInCelsius + "°C" + " " + "is" + " " + tempInFahrenheit + "°F") + // * Now store a fahrenheit temperature into a variable. +// let tempInFahrenheit = 34 // * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." +// celsius = ((5/9)*(fahrenheit-32)) +// let tempInCelsius = (Math.floor((5/9) * (tempInFahrenheit - 32))) +// console.log(tempInFahrenheit + " " + "°F" + " " + "is" + " " + tempInCelsius + " " + "°C" ) // ## Problem Five // Grades Calculator: // * Store Alices's grade on a test to a variable + // * Store Bob's grade on a test to a variable // * Store Cam's grade on a test to a variable // * Find the average grade of all students From f793d541483df5259296311e2b28c24999560fdb Mon Sep 17 00:00:00 2001 From: Coreen Cooper Date: Tue, 8 Dec 2020 17:41:08 -0500 Subject: [PATCH 05/11] solve problem 5 --- problems/variables.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/problems/variables.js b/problems/variables.js index 7495c4e..c76e9af 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -71,19 +71,34 @@ // ## Problem Five - // Grades Calculator: // * Store Alices's grade on a test to a variable +// let alicesGrade = 80 // * 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 = 99 + // * Find the average grade of all students +// let allGrades = (alicesGrade + bobsGrade + camsGrade) +// console.log(allGrades + " " + "is the total of all grades.") +// let averageGrade = Math.round((alicesGrade + bobsGrade + camsGrade)/3) +// let averageGrade = Math.round(allGrades/3) +// console.log(averageGrade + " " + "is the average grade.") + // * Store Dee's grade on a test to a variable +// let deesGrade = 85 + // * Find the average grade of all students +// let classAverage = Math.round((deesGrade+allGrades)/4) +// console.log(classAverage + " " + "is the class average.") + // * Print out if Dee's grade is higher than the class average +// console.log(deesGrade + " " + "is Dee's grade which is higher than the class average.") // ## Problem Six - // Find the last number: // * You are given a number a. Print the last digit of a. // * Example From 00abf1f44f9288e71d67fff528e0dd3c84b5d67a Mon Sep 17 00:00:00 2001 From: Coreen Cooper Date: Tue, 8 Dec 2020 17:51:00 -0500 Subject: [PATCH 06/11] solve problem 6 --- problems/variables.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/variables.js b/problems/variables.js index c76e9af..e731aae 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -106,7 +106,7 @@ // * a = 123 // * Output: // * 3 - +console.log(123%5) // Hint: // Use the remainder % operator. From 39a061d8771f390f71e95842e1c143abe57de633 Mon Sep 17 00:00:00 2001 From: Coreen Cooper Date: Tue, 8 Dec 2020 18:17:40 -0500 Subject: [PATCH 07/11] solve problem 7 --- problems/variables.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/problems/variables.js b/problems/variables.js index e731aae..71f14f8 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -106,13 +106,12 @@ // * a = 123 // * Output: // * 3 -console.log(123%5) // Hint: // Use the remainder % operator. +//console.log(123%5) // ## Problem Seven - // Alice's Age // * x years from now Alice will be y times older than her brother Bob. Bob is 12 years old. How old is Alice? // * Example 1 @@ -122,6 +121,12 @@ console.log(123%5) // * bob = 12 // * Expected values: // * alice = 27 +// console.log((12 + 3) * 2 - 3) I saw the hint after solving +//console.log(2 * (12 + 3) - 3) +// let x = 4 +// let y = 3 +// let bobsAge = 12 +// console.log((bobsAge + x) * y - x) I saw the hint after solving // // * Example 2 // * Input: @@ -134,6 +139,8 @@ console.log(123%5) // * Hint: // * alice + x = y * (bob + x) // * Solve for alice +// alice = y * (bob + x) - x +// console.log(3 * (12 + 1) - 1) // ## Problem Eight From ed0e8b204ff52d98a2ca5e047cac990ef7da0ef4 Mon Sep 17 00:00:00 2001 From: Coreen Cooper Date: Tue, 8 Dec 2020 18:21:06 -0500 Subject: [PATCH 08/11] change Math.floor to Math.round problem 4 --- problems/variables.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/variables.js b/problems/variables.js index 71f14f8..37aeb94 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -66,7 +66,7 @@ // let tempInFahrenheit = 34 // * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." // celsius = ((5/9)*(fahrenheit-32)) -// let tempInCelsius = (Math.floor((5/9) * (tempInFahrenheit - 32))) +// let tempInCelsius = (Math.round((5/9) * (tempInFahrenheit - 32))) // console.log(tempInFahrenheit + " " + "°F" + " " + "is" + " " + tempInCelsius + " " + "°C" ) From 272ba816d085008b726d272e9d7fe4d20c564b01 Mon Sep 17 00:00:00 2001 From: Coreen Cooper Date: Tue, 8 Dec 2020 19:29:37 -0500 Subject: [PATCH 09/11] solve problem 8 --- problems/variables.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/problems/variables.js b/problems/variables.js index 37aeb94..ff258e0 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -154,6 +154,12 @@ // * Output: // * 25% of the daycare animals are cats // * 75% of the daycare animals are dogs +// P% = 20/80 +console.log((20/80) * 100) +let dogs = (60/80) * 100 +let cats = (20/80* 100) +console.log(`The percentage of dogs in the daycare are ${dogs}% and the percentage of cats are ${cats}%.`) + // ## Problem Nine From 53a771b28ce115c72c6ca8b1ad5f8ae0b1c7e16d Mon Sep 17 00:00:00 2001 From: Coreen Cooper Date: Tue, 8 Dec 2020 23:41:40 -0500 Subject: [PATCH 10/11] solve problem 10 and add template literals --- problems/variables.js | 142 ++++++++++++++++++++++-------------------- 1 file changed, 73 insertions(+), 69 deletions(-) diff --git a/problems/variables.js b/problems/variables.js index ff258e0..32d0e89 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -1,71 +1,72 @@ -// ## Problem One - -// Age Calculator: -// * Store your birth year in a constant variable. -//const birthYear = 1975 -//console.log(birthYear) -// * Store a future year in a variable. -//let futureYear = 2020 -// * 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. - -//console.log(futureYear - birthYear) -// * Log them to the screen like so: "I will be either `ageMin` or `ageMax` in `futureYear`", substituting the values. -//let ageMax = (futureYear - birthYear) -//console.log(ageMax) -//let ageMin = ageMax - 1 -//console.log(ageMin) -//console.log("I will be either" + " " + ageMin + " " + "or" + " " + ageMax + " " + "in" + " " + futureYear) - -// ## Problem Two -// Snack Supply Calculator: -// * Store your current age in a variable. +// // ## Problem One + +// // Age Calculator: +// // * Store your birth year in a constant variable. +// const birthYear = 1975 +// console.log(birthYear) +// // * Store a future year in a variable. +// let futureYear = 2020 +// // * 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. + +// //console.log(futureYear - birthYear) +// // * Log them to the screen like so: "I will be either `ageMin` or `ageMax` in `futureYear`", substituting the values. +// // let ageMax = (futureYear - birthYear) +// // console.log(ageMax) +// // let ageMin = ageMax - 1 +// // console.log(ageMin) +// // console.log("I will be either" + " " + ageMin + " " + "or" + " " + ageMax + " " + "in" + " " + futureYear + ".") +// // console.log(`I will be either ${ageMin} or ${ageMax} in ${futureYear}.`) + +// // ## Problem Two +// // Snack Supply Calculator: +// // * Store your current age in a variable. // let currentAge = 45 -// * Store a maximum age in a constant variable. +// // * Store a maximum age in a constant variable. // const maxAge = 45 -// * Store an estimated snack amount per day (as a number). +// // * Store an estimated snack amount per day (as a number). // let snack = 1 -// * Calculate how many snacks you would eat total, from your current age until the maximum age. +// // * Calculate how many snacks you would eat total, from your current age until the maximum age. // let snackNumber = ((currentAge-maxAge) * snack * 365) -// * Log the result to the screen like this: "You will need `snackNumber` to last you until the age of `maxAge`". -// console.log("You will need" + " " + snackNumber + " " + "to last you until the age of" + " " + maxAge + ".") +// // * Log the result to the screen like this: "You will need `snackNumber` to last you until the age of `maxAge`". +// console.log("You will need" + " " + snackNumber + " " + "to last you until the age of" + " " + maxAge + ".") +// console.log(`You will need ${snackNumber} to last you until the age of ${maxAge}.`) -// ## Problem Three +// // ## Problem Three -// Calculate properties of a circle, using the definitions: http://math2.org/math/geometry/circles.htm -// * Store a radius into a variable. +// // Calculate properties of a circle, using the definitions: http://math2.org/math/geometry/circles.htm +// // * Store a radius into a variable. // let radius = 6 - -// * Calculate the circumference based on the radius, and log "The circumference is `circumferenceResult`". -// circumference = 2PI * radius -// console.log(Math.PI) -// console.log((2 * Math.PI) * radius) -// let circumferenceResult = ((2 * 3.141592653589793) * radius) -// console.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 - -// area=PI r**2 -// let areaOfCircle = (3.141592653589793) * (radius**2) -// console.log("The area is" + " " + areaOfCircle) - - -// ## Problem Four -// Temperature Converter: -// * Store a celsius temperature into a variable. +// // * Calculate the circumference based on the radius, and log "The circumference is `circumferenceResult`". +// // circumference = 2PI * radius // note to self +// // console.log(Math.PI) //note to self +// // console.log((2 * Math.PI) * radius) // note to self +// let circumferenceResult = (Math.round(2 * 3.141592653589793) * radius) +// // console.log("The circumference is" + " " + circumferenceResult + ".") +// console.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 +// //area=PI r**2 // note to self +// let areaOfCircle = (Math.round(3.141592653589793) * (radius**2)) +// // console.log("The area is" + " " + areaOfCircle + ".") +// console.log(`The area is ${areaOfCircle}.`) + + +// // ## Problem Four +// // Temperature Converter: +// // * Store a celsius temperature into a variable. // let tempInCelsius = 1 - -// * Convert it to fahrenheit and output "`tempInCelsius`°C is `tempInFahrenheit`°F". -// (celsius * (9/5)+32)=fahrenheit +// // * Convert it to fahrenheit and output "`tempInCelsius`°C is `tempInFahrenheit`°F". +// // (celsius * (9/5)+32)=fahrenheit // note to self // let tempInFahrenheit = (tempInCelsius * (9/5) + 32) -// console.log(tempInCelsius + "°C" + " " + "is" + " " + tempInFahrenheit + "°F") +// //console.log(tempInCelsius + "°C" + " " + "is" + " " + tempInFahrenheit + "°F" + ".") +// console.log(`${tempInCelsius}°C is ${tempInFahrenheit}°F.`) -// * Now store a fahrenheit temperature into a variable. +// // * Now store a fahrenheit temperature into a variable. // let tempInFahrenheit = 34 -// * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." -// celsius = ((5/9)*(fahrenheit-32)) +// // * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." +// // celsius = ((5/9)*(fahrenheit-32)) // note to self // let tempInCelsius = (Math.round((5/9) * (tempInFahrenheit - 32))) // console.log(tempInFahrenheit + " " + "°F" + " " + "is" + " " + tempInCelsius + " " + "°C" ) @@ -125,7 +126,8 @@ //console.log(2 * (12 + 3) - 3) // let x = 4 // let y = 3 -// let bobsAge = 12 +// let bobsAgeNow = 12 +// let alicesAge = (y * (bobsAgeNow + x) - x) // console.log((bobsAge + x) * y - x) I saw the hint after solving // // * Example 2 @@ -141,6 +143,7 @@ // * Solve for alice // alice = y * (bob + x) - x // console.log(3 * (12 + 1) - 1) +// console.log(`${x} years from Alice will be ${y} times older than her brother Bob. Bob is 12 years old. Alice is ${alicesAge}.`) // ## Problem Eight @@ -154,11 +157,11 @@ // * Output: // * 25% of the daycare animals are cats // * 75% of the daycare animals are dogs -// P% = 20/80 -console.log((20/80) * 100) -let dogs = (60/80) * 100 -let cats = (20/80* 100) -console.log(`The percentage of dogs in the daycare are ${dogs}% and the percentage of cats are ${cats}%.`) +// P% = 20/80 // note to self +// console.log((20/80) * 100) //note to self +// let dogs = (60/80 * 100) +// let cats = (20/80* 100) +// console.log(`The percentage of dogs in the daycare are ${dogs}% and the percentage of cats are ${cats}%.`) // ## Problem Nine @@ -171,7 +174,7 @@ console.log(`The percentage of dogs in the daycare are ${dogs}% and the percenta // * The above rule is valid except that every 100 years special rules apply. // * 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. - +console.log("ran out of time to solve, but I will keep trying. Got stuck on the math.") // ## Problem Ten: Predict the output @@ -182,22 +185,23 @@ console.log(`The percentage of dogs in the daycare are ${dogs}% and the percenta // 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. -// ```js +// // c. +// // ```js // let string = 'My favorite number is '; // let number = 42 // let sentence = string + number -// console.log(typeof(sentence)) -// ``` +// console.log(typeof(sentence)) // string +// // My original answer was 'My favorite number is 42' because I missed typeof. +// // ``` From b289cb5048551b0f6df0d93bb288d0de7b6e006a Mon Sep 17 00:00:00 2001 From: Coreen Cooper Date: Sat, 19 Dec 2020 02:56:39 -0500 Subject: [PATCH 11/11] solve problem 9 --- problems/variables.js | 67 +++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/problems/variables.js b/problems/variables.js index 32d0e89..06e8848 100644 --- a/problems/variables.js +++ b/problems/variables.js @@ -35,7 +35,7 @@ // // ## Problem Three -// // Calculate properties of a circle, using the definitions: http://math2.org/math/geometry/circles.htm +// // Calculate properties of a circle, using the definitions: http://math2.org/math/geometry/circles.htm // // * Store a radius into a variable. // let radius = 6 // // * Calculate the circumference based on the radius, and log "The circumference is `circumferenceResult`". @@ -52,7 +52,6 @@ // // console.log("The area is" + " " + areaOfCircle + ".") // console.log(`The area is ${areaOfCircle}.`) - // // ## Problem Four // // Temperature Converter: // // * Store a celsius temperature into a variable. @@ -70,7 +69,6 @@ // let tempInCelsius = (Math.round((5/9) * (tempInFahrenheit - 32))) // console.log(tempInFahrenheit + " " + "°F" + " " + "is" + " " + tempInCelsius + " " + "°C" ) - // ## Problem Five // Grades Calculator: // * Store Alices's grade on a test to a variable @@ -85,7 +83,7 @@ // * Find the average grade of all students // let allGrades = (alicesGrade + bobsGrade + camsGrade) // console.log(allGrades + " " + "is the total of all grades.") -// let averageGrade = Math.round((alicesGrade + bobsGrade + camsGrade)/3) +// let averageGrade = Math.round((alicesGrade + bobsGrade + camsGrade)/3) // let averageGrade = Math.round(allGrades/3) // console.log(averageGrade + " " + "is the average grade.") @@ -103,7 +101,7 @@ // Find the last number: // * You are given a number a. Print the last digit of a. // * Example -// * Input: +// * Input: // * a = 123 // * Output: // * 3 @@ -111,31 +109,30 @@ // Use the remainder % operator. //console.log(123%5) - // ## Problem Seven // Alice's Age // * x years from now Alice will be y times older than her brother Bob. Bob is 12 years old. How old is Alice? // * Example 1 -// * Input: +// * Input: // * x = 3 // * y = 2 // * bob = 12 -// * Expected values: +// * Expected values: // * alice = 27 // console.log((12 + 3) * 2 - 3) I saw the hint after solving //console.log(2 * (12 + 3) - 3) // let x = 4 -// let y = 3 +// let y = 3 // let bobsAgeNow = 12 // let alicesAge = (y * (bobsAgeNow + x) - x) // console.log((bobsAge + x) * y - x) I saw the hint after solving -// +// // * Example 2 -// * Input: +// * Input: // * x = 1 // * y = 3 // * bob = 12 -// * Expected values: +// * Expected values: // * alice = 38 // * Hint: @@ -150,9 +147,9 @@ // * Cat and Dog Percentages // * An animal daycare consists of `numberOfCats` cats and `numberOfDogs` dogs. // * Print the percentage of dogs in the daycare followed by the percentage of cats in the class. The percentage should be printed rounded down to the nearest integer. For example 33.333333333333 will be printed as 33. -// * Example +// * Example // * Input -// * numberOfCats = 20 +// * numberOfCats = 20 // * numberOfDogs = 60 // * Output: // * 25% of the daycare animals are cats @@ -163,24 +160,40 @@ // let cats = (20/80* 100) // console.log(`The percentage of dogs in the daycare are ${dogs}% and the percentage of cats are ${cats}%.`) - // ## Problem Nine // * Leap Year Calculator -// * Given a year, determine if it's a leap year. -// * A leap year is a year containing an extra day. It has 366 days instead of the normal 365 days. -// * The extra day is added in February, which has 29 days instead of the normal 28 days. -// * Leap years occur every 4 years. 2012 was a leap year and 2016 will also be a leap year. -// * The above rule is valid except that every 100 years special rules apply. -// * Years that are divisible by 100 are not leap years if they are not also divisible by 400. +// * Given a year, determine if it's a leap year. +// * A leap year is a year containing an extra day. It has 366 days instead of the normal 365 days. +// * The extra day is added in February, which has 29 days instead of the normal 28 days. +// * Leap years occur every 4 years. 2012 was a leap year and 2016 will also be a leap year. +// * The above rule is valid except that every 100 years special rules apply. +// * 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. -console.log("ran out of time to solve, but I will keep trying. Got stuck on the math.") + +// function leapYear(year) { +// if (year % 400 === 0) { +// return `${year} is a leap year.`; +// } else if (year % 100 === 0) { +// return `${year} is not a leap year.`; +// } else if (year % 4 === 0) { +// return `${year} is a leap year.`; +// } else { +// return `${year} is not a leap year.`; +// } +// } + +// console.log(leapYear(2001)); +// console.log(leapYear(2016)); +// console.log(leapYear(2000)); +// console.log(leapYear(1900)); + // ## 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. +// a. // ```js // let num1 = 2 // let num2 = 5 @@ -188,14 +201,14 @@ console.log("ran out of time to solve, but I will keep trying. Got stuck on the // console.log(num3) // 10 // ``` -// b. +// b. // ```js -// let str = 'jel' +// let str = 'jel' // str += 'lo' // console.log(str) // 'jello' // ``` -// // c. +// // c. // // ```js // let string = 'My favorite number is '; // let number = 42 @@ -203,5 +216,3 @@ console.log("ran out of time to solve, but I will keep trying. Got stuck on the // console.log(typeof(sentence)) // string // // My original answer was 'My favorite number is 42' because I missed typeof. // // ``` - -