diff --git a/README.md b/README.md index 5b384e4b..8aef9499 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Introduction To JavaScript -The module challenge is the afternoon project or assignment that students work through independently. This expands on the guided project completed earlier with the instructor. +> The module challenge is the afternoon project or assignment that students work through independently. This expands on the guided project completed earlier with the instructor. ## Advanced CSS and JavaScript diff --git a/index.js b/index.js index e2ebbd6a..d6a93768 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,10 @@ Do the following: HINT: no function required */ - +const votingAge = 18; +if(votingAge >= 18){ + console.log(true); +} /* Task 1b - Values (not auto tested) @@ -34,22 +37,27 @@ Do the following: HINT: no function required */ - - - +let firstThing = 10; +let secondThing = 20; +if(firstThing === secondThing){ + firstThing = 30; +} +console.log(firstThing); /* Task 1c - Convert Strings to Numbers (not auto tested) Do the following: - 1. Declare a variable with the string type value of "1999" + 1. Declare a variable with the string type value of "1999" 2. Convert the string value of "1999" to a integer value of 1999 3. Console log the result HINT: look up the Number method */ - +const string = "1999"; +let number = Number(string); +console.log(number); /* @@ -64,6 +72,7 @@ Do the following: function multiply(num1, num2){ return num1 * num2; } +console.log(multiply(2, 3)); @@ -77,9 +86,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; } +console.log(dogYears(15)); @@ -129,10 +139,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(weight <= 5){ + return weight * 0.05; + }else if(weight <= 10){ + return weight * 0.04; + }else if(weight <= 15){ + return weight * 0.03; + }else{ + return weight * 0.02; + } + }else{ + console.log("age less one") + if(age <= 0.33){ + return weight * 0.1; + }else if(age <= 0.58){ + return weight * 0.05; + }else{ + return weight * 0.04; + } + } } +console.log(hungryDog(25, 3)); + /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -157,9 +188,20 @@ RULES OF THE GAME: Scissors beats Paper | Paper beats Rock | Rock beats 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 === "scissors" && computer === "paper"){ + return "you win!"; + }else if(user === "paper" && computer === "rock"){ + return "you win!"; + }else{ + return "you lose!"; + } +} +console.log(game("rock","paper")) /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -173,11 +215,12 @@ 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 ){ + const miles = kilometers * 0.621371; + return miles; } - +console.log(miles(100)); //Task 5b - Centimeters to Feet /* @@ -187,10 +230,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(cm) { + const feet = cm / 30.48; + return feet; } - + console.log(feet(10)); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -207,10 +251,12 @@ 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(number){ + return `${number} bottles of soda on the wall, ${number} bottles of soda, take one down pass it around ${number-1} bottles of soda on the wall` + +} +console.log(annoyingSong()); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -227,8 +273,19 @@ 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(score){ + if(score >= 90){ + return "you got an A"; + }else if(score >=80){ + return "you got a B"; + }else if(score >=70){ + return "you got a C"; + }else if(score >=60){ + return "you got a D"; + }else{ + return "you got an F"; + + } }