From c79a50f23b63a416d44edb10665d755e71ed6653 Mon Sep 17 00:00:00 2001 From: Jomar Banting Date: Tue, 10 Jan 2023 04:30:09 -0500 Subject: [PATCH] solved all the task --- index.js | 116 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 96 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index e2ebbd6a5..666efa4da 100644 --- a/index.js +++ b/index.js @@ -19,8 +19,10 @@ Do the following: HINT: no function required */ - - +const votingAge = 18; +if (votingAge >= 18) { + console.log("true"); +} /* Task 1b - Values (not auto tested) @@ -33,6 +35,13 @@ Do the following: HINT: no function required */ +let firstThing = 5; +let secondThing = 10; + +if (firstThing <= secondThing) { + firstThing = 20 + console.log(firstThing); +} @@ -48,7 +57,9 @@ Do the following: HINT: look up the Number method */ - +let firstString = "1999"; +firstString = parseInt(firstString); +console.log(firstString); @@ -64,6 +75,9 @@ Do the following: function multiply(num1, num2){ return num1 * num2; } +multiply(2, 5); + + @@ -77,9 +91,10 @@ Do the following: 3. Return the newly calculated age */ -function dogYears(/*add your code here*/){ - /*add your code here*/ +function dogYears(age){ + return age * 7 } +dogYears(5); @@ -129,10 +144,31 @@ NOTE 2: This is a great time to check the tests to see what it expects, versus w So, on this one test, the weight would be 4 pounds, and the age would be 1 years old. It's expecting your function to return a decimal number of 0.2 */ -function hungryDog(/*add your code here*/){ - /*add your code here*/ +function hungryDog(weight, age){ + if (age < 1) { + if (age >= (2/12) && age <= (4/12)){ + return (weight * .1); + } else if (age >= (4/12) && age <= (7/12)){ + return (weight * .05); + } else if (age >= (7/12) && age <= (12/12)){ + return (weight * .04); + } + + } + else { + if (weight <= 5 ){ + return (weight * 0.05); + } else if (weight >= 6 && weight <= 10){ + return (weight * 0.04); + } else if (weight >= 11 && weight <= 15){ + return (weight * 0.03); + } else { + return (weight * 0.02) + } + } + } - +hungryDog(15, 1); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -155,10 +191,28 @@ Use the game function below to do the following: RULES OF THE GAME: Scissors beats Paper | Paper beats Rock | Rock beats Scissors | Or there's a tie */ - +let computerChoice = Math.floor(Math.random() * (3 - 1 + 1) + 1); +if (computerChoice === 1) { + computerChoice = "rock" +} else if (computerChoice === 2) { + computerChoice = "paper" +} else { + computerChoice = "scissors" +} function game(user, computer){ - /*add your code here*/ + if (user === computer){ + return "it's a tie"; + } else 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 { + return "you lose!"; + } } +game("paper", computerChoice); @@ -173,8 +227,8 @@ 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 * 0.621371; } @@ -187,8 +241,8 @@ 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(cm){ + return cm / 30.48; } @@ -207,8 +261,11 @@ Using the annoyingSong function below do the following: 4. Each time the annoyingSong is run from this loop, it should console.log the string that was returned. */ -function annoyingSong(/*add your code here*/){ - /*add your code here*/ +function annoyingSong(startingNumber){ + return startingNumber + " bottles of soda on the wall, " + startingNumber + " bottles of soda, take one down pass it around " + (startingNumber - 1) + " bottles of soda on the wall"; +} +for (let i = 10; i > 0; i--) { + console.log(annoyingSong(i)); } @@ -227,8 +284,27 @@ 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(yourGrade){ +if (yourGrade >= 90 && yourGrade <= 100) +{ + return "you got an A"; +} +else if (yourGrade >= 80 && yourGrade <= 89) +{ +return "you got a B"; +} +else if (yourGrade >= 70 && yourGrade <= 79) +{ +return "you got a C"; +} +else if (yourGrade >= 60 && yourGrade <= 69) +{ +return "you got a D"; +} +else +{ +return "you got an F"; +} } @@ -246,8 +322,8 @@ HINT - try looking up the .includes() method */ -function vowelCounter(/*add your code here*/) { - /*add your code here*/ +function vowelCounter(vowels) { + return vowels.length; }