From b6a6e1fecddcbfabcf78bbd30cf765cae821a64a Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Tue, 11 Aug 2020 13:55:58 -0400 Subject: [PATCH 1/5] initial recommit --- README.md | 3 ++- index.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 33ff22636..82d9ab41f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # 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. - +-ss +-sss ## Advanced CSS and JavaScript ## JavaScript Foundations diff --git a/index.js b/index.js index 73f240372..7d50fb6f7 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) - +console.log("hello cruel world"); //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) From a3ab818af8e8b2da6e17661784232db207b4f990 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Tue, 11 Aug 2020 15:37:32 -0400 Subject: [PATCH 2/5] task 1 & 2 --- index.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 7d50fb6f7..7e61160f5 100644 --- a/index.js +++ b/index.js @@ -2,34 +2,49 @@ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) -console.log("hello cruel world"); - +let votingAge=19; +if (votingAge>18){ + console.log("true"); +} //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 order = 'cold'; +if (order === 'hot'){ +console.log('order coffee'); +} +else if(order === 'cold'){ +console.log('order beer'); +} //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 +//let arrowFunction = (a, b) => a*b; +//console.log(arrowFunction(8,9)); /************************************************************** Task 2 **************************************************************/ //Age in Dog years //write a function that takes your age and returns it to you in dog years - they say that 1 human year is equal to seven dog years +let age = 31; +let dogYear = 7; +let arrowFunction = (age, dogYear) => age*dogYear; - +console.log(arrowFunction(age,dogYear)); /************************************************************** Task 3 **************************************************************/ //Dog feeder From 26ca6c03d9e7753eb6e2aa3a449cd601bd2bc29a Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Tue, 11 Aug 2020 21:07:30 -0400 Subject: [PATCH 3/5] everything but rock paper scissors --- index.js | 82 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 7e61160f5..fd9311d3d 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ let votingAge=19; if (votingAge>18){ - console.log("true"); + console.log("true"); } //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) @@ -30,21 +30,21 @@ console.log(year) //Task d: Write a function to multiply a*b -//let arrowFunction = (a, b) => a*b; +let multiplyFunction = (a, b) => a*b; -//console.log(arrowFunction(8,9)); +console.log(multiplyFunction(8,9)); /************************************************************** Task 2 **************************************************************/ //Age in Dog years //write a function that takes your age and returns it to you in dog years - they say that 1 human year is equal to seven dog years -let age = 31; +let myAge = 31; let dogYear = 7; -let arrowFunction = (age, dogYear) => age*dogYear; +let arrowFunction = (myAge, dogYear) => myAge*dogYear; -console.log(arrowFunction(age,dogYear)); +console.log(arrowFunction(myAge,dogYear)); /************************************************************** Task 3 **************************************************************/ //Dog feeder @@ -63,7 +63,26 @@ console.log(arrowFunction(age,dogYear)); // 7 - 12 months 4% of their body weight // 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 feeder(age, weight){ + if(age >=1 && weight > 15){ + console.log(weight*.02); + }else if(age >1 && weight <= 15 || weight >= 11){ + console.log(weight*.03); + }else if(age>1 && weight <= 10 || weight >= 6){ + console.log(weight*.04); + }else if(age>1 && weight <= 5){ + console.log(weight*.05); + }else if(age<=.999||age>=.584){ + console.log(weight*.04) + }else if(age<=.583||age>=.334){ + console.log(weight*.05) + }else if(age<=.333||age>=.166){ + console.log(weight*.1) + } +} +feeder(1, 15) @@ -75,30 +94,35 @@ console.log(arrowFunction(age,dogYear)); // 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 - - +let choice="rock"; +function compChoice() /************************************************************** Task 5 **************************************************************/ //Metric Converter //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles +let kilometers = 1; +console.log (kilometers/1.609) - - -//b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters +// b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters +let feet = 1; - - - +console.log (feet*30.48); /************************************************************** 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` +let bottles = 99 - +function annoyingSong(bottles){ + for(let i = bottles; i >= 0; i--){ + console.log( i + " bottles of soda on the wall " + i + " bottles of soda, take one down pass it around " + (i-1) + " bottles of soda on the wall"); +} +} +annoyingSong(bottles) /************************************************************** Task 7 **************************************************************/ @@ -110,6 +134,25 @@ console.log(arrowFunction(age,dogYear)); //60s should be D //and anything below 60 should be F +function mark(grade){ + if(grade >=90 && grade <=100){ + console.log("A"); + }else if(grade <=89 && grade >=80){ + console.log("B"); + }else if(grade <=79 && grade >=70){ + console.log("C"); + }else if(grade <=69 && grade >= 60){ + console.log("D"); + }else if(grade <=59) + console.log("F") + } + + +mark(55); +mark(82); +mark(66); +mark(95); +mark(77); @@ -125,9 +168,4 @@ console.log(arrowFunction(age,dogYear)); /************************************************************** 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 From 428f6a6a70a78f1f871da8e8b2954bebc7dad2b2 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Tue, 11 Aug 2020 22:16:49 -0400 Subject: [PATCH 4/5] everything but shoot functionality --- index.js | 91 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 28 deletions(-) diff --git a/index.js b/index.js index fd9311d3d..7ade663bc 100644 --- a/index.js +++ b/index.js @@ -94,9 +94,44 @@ feeder(1, 15) // 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 -let choice="rock"; -function compChoice() +let compChoice = Math.random(); + let myChoice = "paper"; + +if(compChoice>=0 && compChoice<=.333){ + console.log("computer throws rock") +}else if(compChoice>=.334 && compChoice<=.666){ + console.log("computer throws paper") +}else if(compChoice>=.667 && compChoice<=1){ + console.log("computer throws scissors") +} + +if(myChoice === "rock" || myChoice === "paper" || myChoice === "scissors"){ + console.log("you threw " + myChoice) +} + +function shoot(myChoice, compChoice){ + if(myChoice === "rock" && compChoice === "computer throws rock"){ + console.log("draw") + }else if(myChoice === "paper" && compChoice === "computer throws paper"){ + console.log("draw") + }else if(myChoice === "scissors" && compChoice === "computer throws scissors"){ + console.log("draw") + }else if(myChoice === "rock" && compChoice === "computer throws paper"){ + console.log("you lose (computer wins)") + }else if(myChoice === "rock" && compChoice === "computer throws scissors"){ + console.log("you win (computer loses)") + }else if(myChoice === "paper" && compChoice === "computer throws scissors"){ + console.log("you lose (computer wins)") + }else if(myChoice === "paper" && compChoice === "computer throws rock"){ + console.log("you win (computer loses)") + }else if(myChoice === "scissors" && compChoice === "computer throws rock"){ + console.log("you lose (computer wins)") + }else if(myChoice === "scissors" && compChoice === "computer throws paper"){ + console.log("you win (computer loses)") + } +} +shoot(myChoice, compChoice) /************************************************************** Task 5 **************************************************************/ //Metric Converter //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles @@ -115,14 +150,14 @@ console.log (feet*30.48); // 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` -let bottles = 99 +// let bottles = 99 -function annoyingSong(bottles){ - for(let i = bottles; i >= 0; i--){ - console.log( i + " bottles of soda on the wall " + i + " bottles of soda, take one down pass it around " + (i-1) + " bottles of soda on the wall"); -} -} -annoyingSong(bottles) +// function annoyingSong(bottles){ +// for(let i = bottles; i >= 0; i--){ +// console.log( i + " bottles of soda on the wall " + i + " bottles of soda, take one down pass it around " + (i-1) + " bottles of soda on the wall"); +// } +// } +// annoyingSong(bottles) /************************************************************** Task 7 **************************************************************/ @@ -134,25 +169,25 @@ annoyingSong(bottles) //60s should be D //and anything below 60 should be F -function mark(grade){ - if(grade >=90 && grade <=100){ - console.log("A"); - }else if(grade <=89 && grade >=80){ - console.log("B"); - }else if(grade <=79 && grade >=70){ - console.log("C"); - }else if(grade <=69 && grade >= 60){ - console.log("D"); - }else if(grade <=59) - console.log("F") - } - - -mark(55); -mark(82); -mark(66); -mark(95); -mark(77); +// function mark(grade){ +// if(grade >=90 && grade <=100){ +// console.log("A"); +// }else if(grade <=89 && grade >=80){ +// console.log("B"); +// }else if(grade <=79 && grade >=70){ +// console.log("C"); +// }else if(grade <=69 && grade >= 60){ +// console.log("D"); +// }else if(grade <=59) +// console.log("F") +// } + + +// mark(55); +// mark(82); +// mark(66); +// mark(95); +// mark(77); From bab06cebd1c9d92d792447bce505db5a1c9a51c3 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Wed, 12 Aug 2020 09:35:37 -0400 Subject: [PATCH 5/5] rock paper scissors functional --- index.js | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 7ade663bc..084ee86ef 100644 --- a/index.js +++ b/index.js @@ -94,44 +94,47 @@ feeder(1, 15) // 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 + + + + + + let compChoice = Math.random(); let myChoice = "paper"; -if(compChoice>=0 && compChoice<=.333){ - console.log("computer throws rock") -}else if(compChoice>=.334 && compChoice<=.666){ - console.log("computer throws paper") -}else if(compChoice>=.667 && compChoice<=1){ - console.log("computer throws scissors") -} + if(compChoice>=0 && compChoice<=.333){ + console.log("computer throws rock") + }else if(compChoice>=.334 && compChoice<=.666){ + console.log("computer throws paper") + }else if(compChoice>=.667 && compChoice<=1){ + console.log = "computer throws scissors" + } if(myChoice === "rock" || myChoice === "paper" || myChoice === "scissors"){ - console.log("you threw " + myChoice) +console.log("you threw " + myChoice) } -function shoot(myChoice, compChoice){ - if(myChoice === "rock" && compChoice === "computer throws rock"){ + if(myChoice === "rock" && compChoice>=0 && compChoice<=.333){ console.log("draw") - }else if(myChoice === "paper" && compChoice === "computer throws paper"){ + }else if(myChoice === "paper" && compChoice>=.334 && compChoice<=.666){ console.log("draw") - }else if(myChoice === "scissors" && compChoice === "computer throws scissors"){ + }else if(myChoice === "scissors" && compChoice>=.667 && compChoice<=1){ console.log("draw") - }else if(myChoice === "rock" && compChoice === "computer throws paper"){ + }else if(myChoice === "rock" && compChoice>=.334 && compChoice<=.666){ console.log("you lose (computer wins)") - }else if(myChoice === "rock" && compChoice === "computer throws scissors"){ + }else if(myChoice === "rock" && compChoice>=.667 && compChoice<=1){ console.log("you win (computer loses)") - }else if(myChoice === "paper" && compChoice === "computer throws scissors"){ + }else if(myChoice === "paper" && compChoice>=.667 && compChoice<=1){ console.log("you lose (computer wins)") - }else if(myChoice === "paper" && compChoice === "computer throws rock"){ + }else if(myChoice === "paper" && compChoice>=0 && compChoice<=.333){ console.log("you win (computer loses)") - }else if(myChoice === "scissors" && compChoice === "computer throws rock"){ + }else if(myChoice === "scissors" && compChoice>=0 && compChoice<=.333){ console.log("you lose (computer wins)") - }else if(myChoice === "scissors" && compChoice === "computer throws paper"){ + }else if(myChoice === "scissors" && compChoice>=.334 && compChoice<=.666){ console.log("you win (computer loses)") } -} -shoot(myChoice, compChoice) /************************************************************** Task 5 **************************************************************/ //Metric Converter //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles