Skip to content
Open
Show file tree
Hide file tree
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
Binary file added .DS_Store
Binary file not shown.
79 changes: 71 additions & 8 deletions problems/variables.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// ## Problem One

// Age Calculator:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -24,14 +39,25 @@
// * 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:
// * 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."

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

Expand All @@ -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:
Expand All @@ -53,10 +90,11 @@
// * a = 123
// * Output:
// * 3

// Hint:
// Use the remainder % operator.

let a= 153 % 5
console.log (a)

// ## Problem Seven

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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))