From b96ea14409ad5f5bd643fc451805c4214088a1ef Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Tue, 8 Sep 2020 17:09:35 -0600 Subject: [PATCH 1/3] I'm almost finished with the Javascript tasks --- index.js | 90 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 73f240372..0152f5255 100644 --- a/index.js +++ b/index.js @@ -1,25 +1,43 @@ /************************************************************** Task 1: Warm-up! **************************************************************/ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) - - +const votingAge = 18; +if(votingAge >= 18){ + console.log(true); +} else { + console.log(false) +} //Task b: declare a variable and then use a conditional to change the value of that variable based on the value assigned to a second variable (no function required) +let pizzaSlices = 8; +let boxes = 2; +if(boxes === 3){ + pizzaSlices = 8; +} else { + pizzaSlices = 16; +} +console.log(pizzaSlices); //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method - +let year = "1999"; +Number(year); +console.log(year); //Task d: Write a function to multiply a*b +function multiply(a, b){ + return a * b; + } +console.log(multiply(5, 6)); @@ -29,6 +47,12 @@ +function dogYears(age, dogyears){ + return age * dogyears; +} + +console.log(dogYears(25, 7)); + /************************************************************** Task 3 **************************************************************/ @@ -49,6 +73,26 @@ // when you are finished invoke your function with the weight of 15 lbs and the age of 1 year - if your calculations are correct your result should be 0.44999999999999996 +function dogFeeder(weight, age){ + + if(age >= 1 && weight <= 5){ + return weight * .05; + } else if (age >= 1 && weight >= 6 && weight <= 10 ){ + return weight * .04; + } else if (age >= 1 && weight >= 11 && weight <= 15){ + return weight * .03; + } else if (age >= 1 && weight >= 15){ + return weight * .02; + } else if (age >= .1666 && age <= .3333){ + return weight * .1; + } else if (age > .3333 && age <= .5833){ + return weight * .05; + } else if (age > .5833 && age < 1){ + return weight * .04; + } +} + +console.log(dogFeeder(15, 1)); @@ -60,30 +104,44 @@ // use math.random to determine the computers choice // hint while you can complete this with only conditionals based on strings it may help to equate choice to a number - +// function game(rock, paper, scissors){ +// if( = 1 && ){ + +// } +// } /************************************************************** Task 5 **************************************************************/ //Metric Converter //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles +function distanceConverter(km){ + return km * .621371; +} +console.log(distanceConverter(2)); //b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters +function feetConverter(feet){ + return feet * 30.48; +} - - +console.log(feetConverter(2)); /************************************************************** Task 6 **************************************************************/ // 99 bottles of soda on the wall // create a function called annoyingSong // the function should take a starting number as an argument and count down - at each iteration it should log (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(bottles){ + for (let i = 99; i >= 0; i--){ + console.log("i"); + } +} +// console.log(annoyingSong(i)); /************************************************************** Task 7 **************************************************************/ @@ -94,8 +152,21 @@ //70s should be Cs //60s should be D //and anything below 60 should be F - +function grades(number) { + if(number >= 90){ + return "A"; + } else if(number >=80 && number < 90){ + return "B"; + } else if(number >= 70 && number <80){ + return "C"; + } else if(number >= 60 && number < 70){ + return "D"; + } else if(number < 60){ + return "F"; + } +} + @@ -115,4 +186,3 @@ - From 0a435086721676c1187dad52baf84e62e50b7270 Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Tue, 8 Sep 2020 17:22:16 -0600 Subject: [PATCH 2/3] Finished product --- index.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 0152f5255..753ae4a5a 100644 --- a/index.js +++ b/index.js @@ -104,11 +104,22 @@ console.log(dogFeeder(15, 1)); // use math.random to determine the computers choice // hint while you can complete this with only conditionals based on strings it may help to equate choice to a number -// function game(rock, paper, scissors){ -// if( = 1 && ){ - -// } -// } +function game(rock, paper, scissors){ + + if(rock = 1 && paper = 1){ + return "You lost"; + } else if(rock = 1 && scissors = 1){ + return "You won"; + } else if(paper = 1 && rock = 1){ + return "You won"; + } else if (paper = 1 && scissors = 1){ + return "You lost"; + } else if (scissors = 1 && rock = 1){ + return "You lost"; + } else (scissors = 1 && paper = 1){ + return "You won"; + } + } /************************************************************** Task 5 **************************************************************/ @@ -141,7 +152,7 @@ function annoyingSong(bottles){ console.log("i"); } } -// console.log(annoyingSong(i)); + console.log(annoyingSong(i)); /************************************************************** Task 7 **************************************************************/ From e11bb5727cc62ea8637386bcf5ec50129cf0da9e Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Wed, 9 Sep 2020 17:10:59 -0600 Subject: [PATCH 3/3] Reworked the rock, paper, scissors task --- index.js | 69 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 753ae4a5a..9c363a97d 100644 --- a/index.js +++ b/index.js @@ -104,22 +104,53 @@ console.log(dogFeeder(15, 1)); // use math.random to determine the computers choice // hint while you can complete this with only conditionals based on strings it may help to equate choice to a number -function game(rock, paper, scissors){ - - if(rock = 1 && paper = 1){ - return "You lost"; - } else if(rock = 1 && scissors = 1){ - return "You won"; - } else if(paper = 1 && rock = 1){ - return "You won"; - } else if (paper = 1 && scissors = 1){ - return "You lost"; - } else if (scissors = 1 && rock = 1){ - return "You lost"; - } else (scissors = 1 && paper = 1){ - return "You won"; + + +function game(choice){ + if(choice === 'rock'){ + choice = 1; + }else if(choice === 'paper'){ + choice = 2; + }else if(choice === 'scissors'){ + choice = 3; } - } + + + let compChoice = Math.floor(Math.random() * 3 + 1); + + + + if (choice === 1){ + if(compChoice === 3){ + console.log( "You won"); + }else if(compChoice === 2){ + console.log( "You lost"); + }else if(compChoice === 1){ + console.log( "It's a tie"); + } + } + if (choice === 2){ + if(compChoice === 3){ + console.log( "You lost"); + }else if(compChoice === 2){ + console.log( "It's a tie"); + }else if(compChoice === 1){ + console.log( "You won"); + } + } + if (choice === 3){ + if(compChoice === 3){ + console.log( "It's a tie"); + }else if(compChoice === 2){ + console.log( "You won"); + }else if(compChoice === 1){ + console.log( "You lost"); + } + } +} + + +game('rock'); /************************************************************** Task 5 **************************************************************/ @@ -149,7 +180,7 @@ console.log(feetConverter(2)); function annoyingSong(bottles){ for (let i = 99; i >= 0; i--){ - console.log("i"); + console.log(i); } } console.log(annoyingSong(i)); @@ -192,8 +223,4 @@ function grades(number) { /************************************************************** Stretch **************************************************************/ //Take Rock, Paper, Sissors further -//update your rock papers sissors code below to take a prompt from a user using the window object - - - - +//update your rock papers sissors code below to take a prompt from a user using the window object. \ No newline at end of file