-
Notifications
You must be signed in to change notification settings - Fork 166
Vanessa Watson #162
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?
Vanessa Watson #162
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 |
|---|---|---|
|
|
@@ -2,47 +2,128 @@ | |
|
|
||
| // Age Calculator: | ||
| // * Store your birth year in a constant variable. | ||
| "use strict" | ||
| const birthYear = 1982 | ||
| // console.log(birthYear) | ||
|
|
||
| // * Store a future year in a variable. | ||
| let futureYear = 2045 | ||
|
|
||
| // * Calculate your 2 possible ages for that year based on the stored values. | ||
| let ageMax = futureYear - birthYear | ||
| console.log(ageMax) | ||
|
|
||
| let ageMin = ageMax-1 | ||
| console.log(ageMin) | ||
|
|
||
| // * 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 sentence = 'I will be either' + " " + ageMin + " " + 'or' + " " + ageMax + " " + 'in' + " " + futureYear + '.' | ||
| console.log(sentence) | ||
|
|
||
|
|
||
| // ## Problem Two | ||
|
|
||
| // Snack Supply Calculator: | ||
| // * Store your current age in a variable. | ||
| let currentAge = 38 | ||
|
|
||
| // * Store a maximum age in a constant variable. | ||
| const maxAge = 120 | ||
|
|
||
| // * Store an estimated snack amount per day (as a number). | ||
| let snackAmt = 6 | ||
|
|
||
| // * Calculate how many snacks you would eat total, from your current age until the maximum age. | ||
| let snackTotal = (maxAge - currentAge) * snackAmt * 365 | ||
| console.log(snackTotal) | ||
|
|
||
| // * Log the result to the screen like this: "You will need `snackNumber` to last you until the age of `maxAge`". | ||
| let sentence2 = 'You will need' + " " + snackTotal + " " + 'to last you until the age of' + " " + maxAge + '.' | ||
| console.log(sentence2) | ||
|
|
||
| // ## 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 = 8 | ||
|
|
||
| // * Calculate the circumference based on the radius, and log "The circumference is `circumferenceResult`". | ||
| let pI = Math.PI | ||
| let circumferenceResult = 2 * (pI * radius) | ||
| console.log(circumferenceResult) | ||
|
|
||
| let sentenceCircumference = 'The circumference is' + " " + circumferenceResult + '.' | ||
| console.log(sentenceCircumference) | ||
|
|
||
| // * Calculate the area based on the radius, and log "The area is `areaOfCircle`". | ||
| let areaOfCircle = pI * (radius * radius) | ||
|
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. radius * radius is correct but look up Math.pow or other alternate ways to square numbers in Javascript
Author
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. Yes. LOL I tried ^ b/c in my mind that's how you do exponential in calculations but of course, that didn't work. So I wrote it out. And after I had moved on I went back and saw that ** does exponents. So it would be (radius ** 2). Thanks for the feedback. |
||
| console.log(areaOfCircle) | ||
|
|
||
| let sentenceArea = 'The area is' + " " + areaOfCircle + '.' | ||
| console.log(sentenceArea) | ||
|
|
||
| // * Hint: https://www.w3schools.com/jsref/jsref_pi.asp | ||
|
|
||
| // ## Problem Four | ||
|
|
||
| // Temperature Converter: | ||
| // * Store a celsius temperature into a variable. | ||
| let celsius = 40 | ||
|
|
||
| // * Convert it to fahrenheit and output "`tempInCelsius`°C is `tempInFahrenheit`°F". | ||
| let tempInFahrenheit = (celsius * 1.8) + 32 | ||
| console.log(tempInFahrenheit) | ||
|
|
||
| let tempInCelsius = (tempInFahrenheit - 32) / (1.8) | ||
| console.log(tempInCelsius) | ||
|
|
||
| let tempSen1 = tempInCelsius + '°' + 'C' + " " + 'is' + " " + tempInFahrenheit + '°' + 'F' + '.' | ||
| console.log(tempSen1) | ||
|
|
||
| // * Now store a fahrenheit temperature into a variable. | ||
| let fahrenheit = 88 | ||
|
|
||
| // * Convert it to celsius and output "`tempInFahrenheit`°F is `tempInCelsius`°C." | ||
| tempInCelsius = (fahrenheit - 32) / (1.8) | ||
| // Math.floor(tempInCelsius) | ||
| // console.log(tempInCelsius) | ||
| console.log(Math.floor(tempInCelsius)) | ||
|
|
||
| tempInFahrenheit = (tempInCelsius * 1.8) + 32 | ||
| console.log(tempInFahrenheit) | ||
|
|
||
| // console.log(Math.floor(tempInCelsius)) | ||
| let tempSen2 = tempInFahrenheit + '°' + 'F' + " " + 'is' + " " + (Math.floor(tempInCelsius)) + '°' + 'C' + '.' | ||
| console.log(tempSen2) | ||
|
|
||
| // ## Problem Five | ||
|
|
||
| // Grades Calculator: | ||
| // * Store Alices's grade on a test to a variable | ||
| let aliceGrade = 55 | ||
|
|
||
| // * Store Bob's grade on a test to a variable | ||
| let bobGrade = 66 | ||
|
|
||
| // * Store Cam's grade on a test to a variable | ||
| let camGrade = 77 | ||
|
|
||
| // * Find the average grade of all students | ||
| let averageGrade = (aliceGrade + bobGrade + camGrade) / 3 | ||
| console.log(averageGrade) | ||
|
|
||
| // * Store Dee's grade on a test to a variable | ||
| let deeGrade = 88 | ||
|
|
||
| // * Find the average grade of all students | ||
| averageGrade = (aliceGrade + bobGrade + camGrade + deeGrade) /4 | ||
| console.log(averageGrade) | ||
|
|
||
| // * Print out if Dee's grade is higher than the class average | ||
| let gradeReport = 'Dee' + "'s" + " " + "grade of" + " " + deeGrade + " is higher than the class average of " + averageGrade + '.' | ||
| console.log(gradeReport) | ||
|
|
||
| // ## Problem Six | ||
|
|
||
|
|
@@ -53,6 +134,10 @@ | |
| // * a = 123 | ||
| // * Output: | ||
| // * 3 | ||
| let a = 2603 | ||
|
|
||
| let finalDigit = a % 2600 | ||
|
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. This is correct, but only for your one input case. Think about an answer that could be correct universally |
||
| console.log(Math.floor(finalDigit)) | ||
|
|
||
| // Hint: | ||
| // Use the remainder % operator. | ||
|
|
@@ -70,6 +155,14 @@ | |
| // * Expected values: | ||
| // * alice = 27 | ||
| // | ||
| let x = 8 | ||
| let y = 2 | ||
| let bob2 = 12 | ||
| let alice = (y * (bob2 + x)) | ||
| // let alice = aliceAge + x | ||
|
|
||
| console.log(alice) | ||
|
|
||
| // * Example 2 | ||
| // * Input: | ||
| // * x = 1 | ||
|
|
@@ -86,7 +179,9 @@ | |
|
|
||
| // * Cat and Dog Percentages | ||
| // * An animal daycare consists of `numberOfCats` cats and `numberOfDogs` dogs. | ||
| // * Print the percentage of dogs in the daycare followed by the percentage of cats in the class. The percentage should be printed rounded down to the nearest integer. For example 33.333333333333 will be printed as 33. | ||
| // * Print the percentage of dogs in the daycare followed by the percentage of cats in the class. | ||
| // The percentage should be printed rounded down to the nearest integer. | ||
| // For example 33.333333333333 will be printed as 33. | ||
| // * Example | ||
| // * Input | ||
| // * numberOfCats = 20 | ||
|
|
@@ -95,6 +190,14 @@ | |
| // * 25% of the daycare animals are cats | ||
| // * 75% of the daycare animals are dogs | ||
|
|
||
| let numberOfCats = 75 | ||
| let numberOfDogs = 25 | ||
|
|
||
| let daycareTotal = 100 | ||
|
|
||
| console.log(`${(numberOfCats / daycareTotal) * 100}% of the daycare animals are cats`) | ||
| console.log(`${(numberOfDogs / daycareTotal) * 100}% of the daycare animals are dogs`) | ||
|
|
||
| // ## Problem Nine | ||
|
|
||
| // * Leap Year Calculator | ||
|
|
@@ -109,29 +212,52 @@ | |
|
|
||
| // ## 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. | ||
| // 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) | ||
| // 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 sentence3 = string + number // I used sentence several times above in this assigment | ||
| console.log(typeof(sentence3)) | ||
|
|
||
|
|
||
|
|
||
| function sum(){ | ||
| let x = 15; | ||
| let y = 8; | ||
| return x + y | ||
| } | ||
| console.log(sum()) | ||
|
|
||
|
|
||
|
|
||
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.
Love that you stored this in a variable!