diff --git a/index.js b/index.js index 29056f05f..264e90c8b 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,9 @@ Do the following: HINT: no function required */ - +let votingAge = 21; +if (votingAge >= 18) {console.log(true)} +else {console.log(false)}; /* Task 1b - Values @@ -31,7 +33,10 @@ Do the following: HINT: no function required */ - +let varOne = 'boo'; +let varTwo = 10; +if (varTwo === 10){varOne = 'who'} +console.log(varOne) @@ -46,7 +51,9 @@ Do the following: HINT: look up the Number method */ - +let strToNum = '1999'; +Number(strToNum) +console.log(strToNum) /* @@ -58,10 +65,11 @@ Do the following: 3. Multiply a and b and return the answer */ -function multiply(/*add your code here*/){ - /*add your code here*/ +function multiply(numOne, numTwo){ + let result = numOne * numTwo; + return result; } - +console.log(multiply(5,2)) /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -74,10 +82,13 @@ Do the following: 3. Return the newly calculated age */ -function dogYears(/*add your code here*/){ - /*add your code here*/ +function dogYears(age){ + let dogAge = age * 7; + return dogAge } +console.log(dogYears(7)); + /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -107,10 +118,26 @@ Use the hungryDog function and feeding requirements below to do the following: NOTE: If done correctly, a weight of 15 lbs and age of 1 year would return 0.44999999999999996 */ -function hungryDog(/*add your code here*/){ - /*add your code here*/ +function hungryDog(weight, age){ + if (age >= 1) { + if (weight <5) { + return weight * .05 + } else if (weight>= 6 && weight <=10) { + return weight * .04 + } else if (weight >= 11 && weight <=15) { + return weight * .03 + } else { + return weight * .02 + } + } + if (age> .166 && age < .33) { + return weight * .1 + } else if (age >= .33 && age <=.583) { + return weight * .05 + } else {return weight *.04} } + console.log(hungryDog(15, 1)) /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -134,9 +161,61 @@ Use the game function below to do the following: HINT: Remember that the order in which we pass in our arguments matters when it comes to parameters */ +let user = Math.round(Math.random()*2) + if (user === 0) + { + user = 'rock' + } + else if (user === 1) + { + user = 'paper' + } + else + { + user = 'scissors' + }; + + +let computer = Math.round(Math.random()*2) + if (computer === 0) + { + computer = 'rock' + } + else if (computer === 1) + { + computer = 'paper' + } + else + { + computer = 'scissors' + }; + + function game(user, computer){ - /*add your code here*/ + if (user === 'rock' && computer === 'scissors') + { + return "you win!" + } + else if (user === 'paper' && computer === 'rock') + { + return "you win!" + } + else if (user === 'scissors' && computer === 'paper') + { + return "you win!" + } + else if (user === computer) + { + return "it's a tie" + } + else + { + return "you lose!" + } } +console.log(user); +console.log(computer); +console.log(game(user, computer)); @@ -151,10 +230,10 @@ Using the miles function below do the following: 3. Return the number of miles */ -function miles(/*add your code here*/){ - /*add your code here*/ +function miles(kilometers){ + return kilometers* .621371 } - + console.log(miles (3)); //Task 5b - Feet to CM @@ -165,10 +244,11 @@ Using the feet function below do the following: 3. Return number of feet */ -function feet(/*add your code here*/){ - /*add your code here*/ - } - +function feet(centimeters){ + return centimeters / 30.48 +} + +console.log(feet(60)) /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -181,9 +261,12 @@ Using the annoyingSong function below do the following: "{number} bottles of soda on the wall, {number} bottles of soda, take one down pass it around {number left over} bottles of soda on the wall" */ -function annoyingSong(/*add your code here*/){ - /*add your code here*/ +function annoyingSong(startNum){ + for (let i = startNum; i > 0; i-- ) { + return i + " bottles of soda on the wall, " + i + " bottles of soda, take one down pass it around " + --i + " bottles of soda on the wall"; + } } +console.log(annoyingSong(99)) /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -201,10 +284,22 @@ Using the grade function below do the following: below should return 'you got an F' */ -function grade(/*Your Code here */){ - /*Your Code here */ - } +function grade(grade){ + if (grade <= 100 && grade >= 90) { + return 'you got an A' + } else if (grade <= 89 && grade >= 80) { + return 'you got a B' + } else if (grade <= 79 && grade >= 70) { + return 'you got a C' + } else if (grade <= 69 && grade >= 60) { + return 'you got a D' + } else {return 'you got an F'} +} +console.log(grade(100)) +console.log(grade(86)) +console.log(grade(69)) +console.log(grade(55)) /*💪💪💪💪💪💪💪💪💪💪 Stretch 💪💪💪💪💪💪💪💪💪💪*/