Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 88 additions & 4 deletions problems/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
// * 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 = 1987
let futureYear = 2063
const ageMin = 75
const ageMax = 76
console.log("I will be either " + ageMin + " or " + ageMax + " in " + futureYear)


// ## Problem Two

// Snack Supply Calculator:
Expand All @@ -16,6 +23,16 @@
// * 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 = 33
const maxAge = 100
let daysPerYear = 365
let snacksPerDay = 3
let snackNumber = (daysPerYear * (maxAge - myAge) * snacksPerDay)
//Calculation: 365 days * 67 years * 3 snacks a day = 73,365 snacks
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
Expand All @@ -24,6 +41,16 @@
// * Calculate the area based on the radius, and log "The area is `areaOfCircle`".
// * Hint: https://www.w3schools.com/jsref/jsref_pi.asp

const circleRadius = 10
const circleDiameter = 20
// Diameter is 2 * circleRadius
const circumferenceResult = Math.PI * circleDiameter
console.log("The circumference is " + circumferenceResult)
const areaOfCircle = Math.PI * (Math.pow(circleRadius, 2))
// Area = Pi * radius squared
console.log("The area is " + areaOfCircle)


// ## Problem Four

// Temperature Converter:
Expand All @@ -32,6 +59,13 @@
// * Now store a fahrenheit temperature into a variable.
// * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C."

let tempInCelsius = 50
let tempInFahrenheit = (tempInCelsius * 1.8) + 32
console.log(tempInFahrenheit)

let tempFahrenheit = 120
let tempCelsius = (tempFahrenheit - 32)/1.8
console.log(tempCelsius)

// ## Problem Five

Expand All @@ -44,6 +78,17 @@
// * Find the average grade of all students
// * Print out if Dee's grade is higher than the class average

let alicesGrade = 97
let bobsGrade = 100
let camsGrade = 88
let averageStudentGrade = (alicesGrade + bobsGrade + camsGrade)/3
console.log("The average grade of all 3 students is " + averageStudentGrade)
let deesGrade = 100
let newStudentAverageGrade = (alicesGrade + bobsGrade + camsGrade + deesGrade)/4
console.log("The new average of all 4 students is " + newStudentAverageGrade)
if (newStudentAverageGrade > averageStudentGrade){ console.log("Dee's Score 96.25 ")}


// ## Problem Six

// Find the last number:
Expand All @@ -57,6 +102,7 @@
// Hint:
// Use the remainder % operator.

console.log(123 % 3)

// ## Problem Seven

Expand All @@ -82,6 +128,14 @@
// * alice + x = y * (bob + x)
// * Solve for alice

let x = 3
let y = 2
let bob = 12

let alice = y * (bob + x) - x

console.log(alice)

// ## Problem Eight

// * Cat and Dog Percentages
Expand All @@ -95,6 +149,13 @@
// * 25% of the daycare animals are cats
// * 75% of the daycare animals are dogs

let numberOfCats = 20
let numberOfDogs = 60
let totalNumberOfAnimals = numberOfCats + numberOfDogs
let percentageOfCats = Math.round((numberOfCats/totalNumberOfAnimals)*100)

console.log(percentageOfCats + "% of the daycare animals are cats ")

// ## Problem Nine

// * Leap Year Calculator
Expand All @@ -106,6 +167,18 @@
// * 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.

let year = 2020

let isDivByFour = (year % 4) === 0
let isDivBy100 = (year % 100) === 0
let isDivBy400 = (year % 400) === 0

let isLeapYear = isDivByFour && (!isDivBy100 || isDivBy400)

console.log('Year ' + year + 'is a leap year: ' + isLeapYear)




// ## Problem Ten: Predict the output

Expand All @@ -116,22 +189,33 @@
// let num1 = 2
// let num2 = 5
// let num3 = num1 * num2
// console.log(num3)
// console.log(num3)
// ```
let num1 = 2
let num2 = 5
let num3 = num1 * num2
console.log(num3) //10

// b.
// ```js
// let str = 'jel'
// str += 'lo'
// console.log(str)
// console.log(str)
// ```
let str = 'jel'
str += 'lo'
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))
// ```


let string = 'My favorite number is'
let number = 42
let sentence = string + number
console.log(typeof(sentence)) //String