Skip to content
84 changes: 78 additions & 6 deletions problems/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Age should be numbers on strings

const maxAge = "99"
let snackCount = "3"
let snackNumber = ((maxAge - curAge)*(snackCount * 365))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of equation. This is the type of solution I want to see in Question 1


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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job using Math library. Can also us it for Math.pow(radius, 2)

let circumferenceOfCircle = (Math.PI * radius * 2)
console.log(`The circumference is ${circumferenceOfCircle} and the area is ${areaOfCircle}.`)
// ## Problem Four

// Temperature Converter:
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always use triple equals === (strict equaltiy)

{
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.
Expand All @@ -116,22 +190,20 @@
// 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
// let string = 'My favorite number is ';
// let number = 42
// let sentence = string + number
// console.log(typeof(sentence))
// console.log(typeof(sentence))/string
// ```