-
Notifications
You must be signed in to change notification settings - Fork 166
Auredy Sanchez and Anju Hyppolite Lab #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,86 @@ | ||
| "use strict" | ||
| // ## Problem One | ||
|
|
||
| // Age Calculator: | ||
| // * Store your birth year in a constant variable. | ||
| const birthYear = 1986 | ||
| console.log (birthYear) | ||
|
|
||
| // * Store a future year in a variable. | ||
| let futureYear = 2020 | ||
| console.log (futureYear) | ||
|
|
||
| // * 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. | ||
| // * Log them to the screen like so: "I will be either `ageMin` or `ageMax` in `futureYear`", substituting the values. | ||
| let ageMin = 33; | ||
| let ageMax = 34; | ||
| console.log ("I will be" + " " + ageMin + " " + "or" + " " + ageMax + " " + "in" + " " + futureYear) | ||
|
|
||
| // ## Problem Two | ||
|
|
||
| // Snack Supply Calculator: | ||
| // * Store your current age in a variable. | ||
| let age = 34; | ||
| // * Store a maximum age in a constant variable. | ||
| const maxAge = 40; | ||
| // * Store an estimated snack amount per day (as a number). | ||
| let snackPerday = 4; | ||
| // * 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`". | ||
| console.log ("I will need" + " " + snackPerday + " " + "snacks every day" + " " + "to last me until I turn" + " " + 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 = 10; | ||
| // * Calculate the circumference based on the radius, and log "The circumference is `circumferenceResult`". | ||
| let circumferenceResult = (2 * Math.PI * 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 | ||
| let areaOfCircle = (Math.PI * radius**2) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of Math library. Can also use Math.pow(radius, 2) |
||
| console.log ("The area is" + " " + areaOfCircle) | ||
|
|
||
| // ## Problem Four | ||
|
|
||
| // Temperature Converter: | ||
| // * Store a celsius temperature into a variable. | ||
| let tempInCelsius = 25; | ||
| // * Convert it to fahrenheit and output "`tempInCelsius`°C is `tempInFahrenheit`°F". | ||
| let tempInFahrenheit = (tempInCelsius * 1.8 + 32) | ||
| console.log (tempInCelsius + " " + "is" + " " + tempInFahrenheit) | ||
| // * Now store a fahrenheit temperature into a variable. | ||
| let fahrenheit = 100; | ||
| // * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." | ||
| let celsius = ((fahrenheit - 32) * 5 / 9) | ||
| console.log (fahrenheit + " " + "is" + " " + celsius) | ||
|
|
||
|
|
||
| // ## Problem Five | ||
|
|
||
| // Grades Calculator: | ||
| // * Store Alices's grade on a test to a variable | ||
| let alicesGrade = 95; | ||
| // * 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 = 76; | ||
| // * Find the average grade of all students | ||
| let average = (alicesGrade + bobsGrade + camsGrade) / 3 | ||
| console.log ("The average of Alice's," + " " + "Bob's," + " " + "and" + " " + "Cam's" + " " + "grades is" + " " + average) | ||
| // * Store Dee's grade on a test to a variable | ||
| let deesGrade = 40; | ||
| // * Find the average grade of all students | ||
| let mean = (alicesGrade + bobsGrade + camsGrade + deesGrade) / 4 | ||
| console.log (("The mean of Alice's," + " " + "Bob's," + " " + "Cam's," + " " + "and " + " " + "Dee's" + " " + "grades is" + " " + mean)) | ||
| // * Print out if Dee's grade is higher than the class average | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to added spaces between each word, just between strings and variables. |
||
| let deesResults = 89 | ||
| let classAvg = (alicesGrade + bobsGrade + camsGrade + deesResults) / 4 | ||
| console.log (("The class average of Alice's," + " " + "Bob's," + " " + "Cam's," + " " + "and " + " " + "Dee's" + " " + "grades is" + " " + classAvg)) | ||
|
|
||
|
|
||
| // ## Problem Six | ||
|
|
||
|
|
@@ -57,6 +95,10 @@ | |
| // Hint: | ||
| // Use the remainder % operator. | ||
|
|
||
| let n = 227 | ||
| let lastDigit = n % 10 | ||
| console.log ("The last digit of" + " " + n + " " + "equals" + " " + lastDigit) | ||
|
|
||
|
|
||
| // ## Problem Seven | ||
|
|
||
|
|
@@ -82,6 +124,18 @@ | |
| // * alice + x = y * (bob + x) | ||
| // * Solve for alice | ||
|
|
||
| let y = 2; | ||
| let bobsAge = 12; | ||
| let alicesAge = y * bobsAge; | ||
|
|
||
| let y1 = 3; | ||
| let alicesAge1 = y1 * bobsAge; | ||
|
|
||
| console.log("Alice is either" + " " + alicesAge + " " + "or" + " " + alicesAge1) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| // ## Problem Eight | ||
|
|
||
| // * Cat and Dog Percentages | ||
|
|
@@ -95,6 +149,15 @@ | |
| // * 25% of the daycare animals are cats | ||
| // * 75% of the daycare animals are dogs | ||
|
|
||
| let numberOfCats = 20; | ||
| let numberOfDogs = 60; | ||
| let dogs = .75 * numberOfDogs | ||
| let cats = .25 * numberOfCats | ||
| console.log("There are" + " " + dogs + " " + "dogs" + " " + "and" + " " + cats + " " + "cats" + " " + "in the class") | ||
|
|
||
|
|
||
|
|
||
|
|
||
| // ## Problem Nine | ||
|
|
||
| // * Leap Year Calculator | ||
|
|
@@ -106,32 +169,82 @@ | |
| // * 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. | ||
|
|
||
| //function checkLeapYear(year) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice try! |
||
| //if (year % 4 === 0) | ||
| //if (year % 400 === 0) return leapyear; | ||
| //if (year % 100 === 0) return leapyear;{ | ||
| //console.log(year + 'is not a leap year'); | ||
| //} else { | ||
| //console.log(year + 'is a leap year') | ||
| //} //let years1 = 1900 | ||
| //let years2 = 2000 | ||
|
|
||
|
|
||
|
|
||
| //} | ||
| //console.log(leapyear(2000)); | ||
|
|
||
| //function leapYear(year) { | ||
| //if (year % 400 === 0) return leapYear; | ||
| //if (year % 100 === 0) return leapYear; | ||
| //return year % 4 === 0; | ||
| //} | ||
| //console.log(leapyear(2000)); | ||
|
|
||
| function leapyear(year) { | ||
| if (year % 100 === 0 && year % 400 !== 0) | ||
|
|
||
| return "This is not a leap year"; | ||
| else | ||
| return "This is a leap year"; | ||
|
|
||
|
|
||
|
|
||
| //return (leapyear + str) || (leapyear + str2) | ||
| } | ||
| console.log(leapyear(2016)); | ||
| console.log(leapyear(2012)); | ||
| console.log(leapyear(1900)); | ||
| console.log(leapyear(2000)); | ||
|
|
||
|
|
||
| //function greeting(name) { | ||
| //let str = "Hello"; | ||
| //return str + name; | ||
| //} | ||
| //console.log(greeting("Auredy")); | ||
|
|
||
|
|
||
|
|
||
| // ## 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. | ||
| // ```js | ||
| // let num1 = 2 | ||
| // let num2 = 5 | ||
| // let num3 = num1 * num2 | ||
| // console.log(num3) | ||
| // ``` | ||
| 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) | ||
| // ``` | ||
| 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)) | ||
| // ``` | ||
| let string = 'My favorite number is '; | ||
| let number = 42 | ||
| let sentence = string + number | ||
| console.log(typeof(sentence)) | ||
| // ``` console.log(typeOf(sentence)) // 'My favorite number is 42' (after running the code we realized it was asking us what type of value) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job remembering to use use strict