Skip to content
96 changes: 95 additions & 1 deletion problems/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,47 @@
// * 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 = 1977
let futureYear = 2021
let minimumAge = 44
let maximumAge = 45
console.log("I will be either " + minimumAge + " or " + maximumAge + " in " + futureYear)

// ## Problem Two


// Snack Supply Calculator:
// * Store your current age in a variable.
// * Store a maximum age in a constant variable.
// * Store an estimated snack amount per day (as a number).
// * 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
const maxAge = 99
let snackCount = 3
let snackNumber = ((maxAge - curAge)*(snackCount * 365))

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 = 2
let circumferenceOfCircle = Math.PI * (radius + radius)
let areaOfCircle = Math.PI * (radius * 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

pi * r ^ 2. so radius**2


console.log("The circumference is " +circumferenceOfCircle)
console.log("The area is " +areaOfCircle +".")


// ## Problem Four

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

let celsius = 23
let celsiusToFahrenheit = (celsius * 9/5) + 32

console.log(celsius+"°C" + " is " + celsiusToFahrenheit+"°F.")

fahrenheit = 90.5
let fahrenheitToCelsius = (fahrenheit - 32) * 5/9

console.log(fahrenheit+"°F is " + fahrenheitToCelsius +"°C.")





// ## Problem Five

Expand All @@ -44,6 +81,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
console.log(' The averages of all students is ' + average)
let dee = 90
average = (bob + cam + alice + dee) / 4
console.log ( ' The new average of the all students is ' + average)
if(dee > average ) console.log("Dees grade is higher than average")

// ## Problem Six

// Find the last number:
Expand All @@ -53,6 +100,11 @@
// * a = 123
// * Output:
// * 3

let a = 123
let output = 123 % 10
console.log(output)


// Hint:
// Use the remainder % operator.
Expand All @@ -70,6 +122,14 @@
// * Expected values:
// * alice = 27
//

x = 3
y = 2
bob = 12
alice = (y * (bob + x)- x)
console.log(alice)


// * Example 2
// * Input:
// * x = 1
Expand All @@ -82,6 +142,15 @@
// * alice + x = y * (bob + x)
// * Solve for alice

x = 1
y = 3
bob = 12
alice = (y * (bob + x)- x)
console.log(alice)




// ## Problem Eight

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

let numberOfCats = 100
let numberOfDogs = 150
let percentageOfCats = (numberOfCats/(numberOfDogs + numberOfCats))* 100
let percentageOfDogs = (numberOfDogs/(numberOfDogs + numberOfCats))* 100
console.log( + percentageOfCats + "% of the daycare animals are cats and " + percentageOfDogs + "% of the daycare animals are dogs")

// ## Problem Nine

// * Leap Year Calculator
Expand All @@ -118,13 +193,26 @@
// let num3 = num1 * num2
// 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)
// ```
// "jello"

let str = 'jel'
str += 'lo'
console.log(str)


// c.
// ```js
Expand All @@ -133,5 +221,11 @@
// let sentence = string + number
// console.log(typeof(sentence))
// ```
// "My favorite number is 42"
// string

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