From 37ec37fd0ac9b76a19aea9911b7fd418a8f60c1f Mon Sep 17 00:00:00 2001 From: Seth MacPherson Date: Fri, 21 Aug 2020 12:56:59 -0700 Subject: [PATCH 1/9] Answered first 3 warm up questions --- index.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 73f240372..8a1ec3ffe 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,41 @@ + + /************************************************************** Task 1: Warm-up! **************************************************************/ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) +let votingAge = 18; +// all of my work was done on repl.it because I couldnt figure out how to do it in VSC. +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 num1 = 4; +let num2 = 3; +if (num1 > num2){ + num1 = num1 + num2; + console.log(num1); +} +else { + num2 = num2 - num1; + console.log(num2) +} -//Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method +//Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method +let yearChange = "1999"; +Number(yearChange); +console.log(yearChange); @@ -22,7 +44,6 @@ - /************************************************************** 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 @@ -70,7 +91,6 @@ - //b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters From 9388d27c50b2b865a28e8ad2398828c2fc273e6e Mon Sep 17 00:00:00 2001 From: Seth MacPherson Date: Fri, 21 Aug 2020 13:34:27 -0700 Subject: [PATCH 2/9] setup the outline for the next task. Wrote a little example code to work from later --- index.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/index.js b/index.js index 8a1ec3ffe..d6fb672f6 100644 --- a/index.js +++ b/index.js @@ -41,14 +41,27 @@ console.log(yearChange); //Task d: Write a function to multiply a*b +let total = myFunc(2,3); +function myFunc(a,b){ + return a * b; +} +console.log(total) /************************************************************** 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 myAge = 29; + +let myDogAge = whatAge(); + +function whatAge(){ + return myAge * 7; +} +console.log(myDogAge); @@ -68,6 +81,14 @@ console.log(yearChange); // 4 - 7 months 5% of their body weight // 7 - 12 months 4% of their body weight + +//variables: +//age, weight, foodWeight + +//if (age >= 1){ +// if (weight <=5) { +// foodWeight = weight * .05 + // 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 From 964aa6b89a8be52f0a2af290a75448b2abcfd7ab Mon Sep 17 00:00:00 2001 From: Seth MacPherson Date: Fri, 21 Aug 2020 16:32:02 -0700 Subject: [PATCH 3/9] Wrote out all the if/else if statements for task 3 --- index.js | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index d6fb672f6..369dbfe33 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,10 @@ let votingAge = 18; // all of my work was done on repl.it because I couldnt figure out how to do it in VSC. if (votingAge >= 18) { - console.log(true) + console.log(true); +} +else { + console.log(false); } @@ -82,17 +85,51 @@ console.log(myDogAge); // 7 - 12 months 4% of their body weight -//variables: -//age, weight, foodWeight -//if (age >= 1){ -// if (weight <=5) { -// foodWeight = weight * .05 + // 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 +let age = 1; +let weight = 15; + +function foodWeight (age, weight){ +//this is for 1+ years old until next comment + if (age >= 1){ + if (weight < 6){ + foodWeight = weight * .05; + console.log(foodWeight) + } + else if (weight >= 6 && weight < 11){ + foodWeight = weight * .04; + } + else if (weight 11>= && weight < 15){ + foodWeight = weight * .03; + } + else (weight >=15){ + foodWeight = weight *.02; + } +//start of "under 1 year old" age +//2 months (2/12) - 4 months (4/12) + else if (age >= (2/12) && age < (4/12)){ + foodWeight = weight * .1; + } + else if (age >= (4/12) && age < (7/12){ + foodWeight = weight * .05; + } + else if (age >= (7/12) && age < 1) + foodWeight = weight * .04; + } +} + + + + + + + /************************************************************** Task 4 **************************************************************/ From 2ff95644205b2c3e1c18fc2f17f7ac3c9f8125cb Mon Sep 17 00:00:00 2001 From: Seth MacPherson Date: Fri, 21 Aug 2020 16:53:10 -0700 Subject: [PATCH 4/9] Moved on while waiting for help in #help channel. Wrote the start of RPS game --- index.js | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 369dbfe33..70e74fbc6 100644 --- a/index.js +++ b/index.js @@ -100,27 +100,37 @@ function foodWeight (age, weight){ if (age >= 1){ if (weight < 6){ foodWeight = weight * .05; - console.log(foodWeight) + console.log(foodWeight); } - else if (weight >= 6 && weight < 11){ + else if (weight >= 6 && weight < 11) { foodWeight = weight * .04; + console.log(foodWeight); } - else if (weight 11>= && weight < 15){ + else if (weight >= 11 && weight < 15) { foodWeight = weight * .03; + console.log(foodWeight); } - else (weight >=15){ + else (weight >= 15) { foodWeight = weight *.02; + console.log(foodWeight); } + } //start of "under 1 year old" age //2 months (2/12) - 4 months (4/12) - else if (age >= (2/12) && age < (4/12)){ + else if (age >= (2/12) && age < (4/12)) { foodWeight = weight * .1; + console.log(foodWeight); } - else if (age >= (4/12) && age < (7/12){ +//4 months (4/12) - 7 months (7/12) + else if (age >= (4/12) && age < (7/12) { foodWeight = weight * .05; + console.log(foodWeight); } - else if (age >= (7/12) && age < 1) + +//7 months (7/12) - 11.99 months (>1) + else if (age >= (7/12) && age < 1){ foodWeight = weight * .04; + console.log(foodWeight); } } @@ -139,7 +149,21 @@ function foodWeight (age, weight){ // 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 myHand = "Rock",; + let compChoice = 0; +//Rules - Computers "choice" +//.00 - .33 : Rock +//.33 - .66 : Paper +//.66 - .99 : Scissors + +function rps(myHand){ + let compChoice = math.random(); + let myChoice = myHand.length; + if + +} + /************************************************************** Task 5 **************************************************************/ From 1a637681459950eb3484edabc874ad55141596ae Mon Sep 17 00:00:00 2001 From: Seth MacPherson Date: Fri, 21 Aug 2020 17:00:50 -0700 Subject: [PATCH 5/9] Needed to save --- index.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 70e74fbc6..8f5a51aec 100644 --- a/index.js +++ b/index.js @@ -114,7 +114,7 @@ function foodWeight (age, weight){ foodWeight = weight *.02; console.log(foodWeight); } - } + //start of "under 1 year old" age //2 months (2/12) - 4 months (4/12) else if (age >= (2/12) && age < (4/12)) { @@ -122,7 +122,7 @@ function foodWeight (age, weight){ console.log(foodWeight); } //4 months (4/12) - 7 months (7/12) - else if (age >= (4/12) && age < (7/12) { + else if (age >= (4/12) && age < (7/12){ foodWeight = weight * .05; console.log(foodWeight); } @@ -132,7 +132,7 @@ function foodWeight (age, weight){ foodWeight = weight * .04; console.log(foodWeight); } -} +} //this one closes the function @@ -151,6 +151,7 @@ function foodWeight (age, weight){ let myHand = "Rock",; let compChoice = 0; + let scoreboard = 0; //Rules - Computers "choice" //.00 - .33 : Rock @@ -160,7 +161,10 @@ function foodWeight (age, weight){ function rps(myHand){ let compChoice = math.random(); let myChoice = myHand.length; - if + if (compChoice >= 0 && compChoice < .33) + scoreboard = myChoice - compChoice; + console.log(myChoice); + } @@ -213,8 +217,3 @@ function rps(myHand){ /************************************************************** Stretch **************************************************************/ //Take Rock, Paper, Sissors further //update your rock papers sissors code below to take a prompt from a user using the window object - - - - - From fd86f2635eda55eb5781a18575531679e95ba571 Mon Sep 17 00:00:00 2001 From: Seth MacPherson Date: Fri, 21 Aug 2020 18:28:33 -0700 Subject: [PATCH 6/9] TL Review and Guidance. Back to working on RPS --- index.js | 106 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/index.js b/index.js index 8f5a51aec..5a5b4a0a6 100644 --- a/index.js +++ b/index.js @@ -44,27 +44,23 @@ console.log(yearChange); //Task d: Write a function to multiply a*b -let total = myFunc(2,3); - function myFunc(a,b){ return a * b; } -console.log(total) +console.log(myFunc(2,3)); /************************************************************** 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 myAge = 29; -let myDogAge = whatAge(); -function whatAge(){ +function whatAge(myAge){ return myAge * 7; } -console.log(myDogAge); +console.log(whatAge(29)); @@ -90,51 +86,36 @@ console.log(myDogAge); // 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 - - -let age = 1; -let weight = 15; - function foodWeight (age, weight){ //this is for 1+ years old until next comment if (age >= 1){ if (weight < 6){ - foodWeight = weight * .05; - console.log(foodWeight); + return (weight * .05); } else if (weight >= 6 && weight < 11) { - foodWeight = weight * .04; - console.log(foodWeight); + return (weight * .04); } - else if (weight >= 11 && weight < 15) { - foodWeight = weight * .03; - console.log(foodWeight); + else if (weight >= 11 && weight <= 15) { + return (weight * .03); } - else (weight >= 15) { - foodWeight = weight *.02; - console.log(foodWeight); + else{ + return (weight * .05); + } + } + else{ + if (age < (4/12)) { + return (weight * .1); + } + else if (age < (7/12)){ + return (weight * .05); + } + else{ + return (weight * .04); } - -//start of "under 1 year old" age -//2 months (2/12) - 4 months (4/12) - else if (age >= (2/12) && age < (4/12)) { - foodWeight = weight * .1; - console.log(foodWeight); } -//4 months (4/12) - 7 months (7/12) - else if (age >= (4/12) && age < (7/12){ - foodWeight = weight * .05; - console.log(foodWeight); - } - -//7 months (7/12) - 11.99 months (>1) - else if (age >= (7/12) && age < 1){ - foodWeight = weight * .04; - console.log(foodWeight); } -} //this one closes the function - +console.log(foodWeight(1, 15)); @@ -149,24 +130,45 @@ function foodWeight (age, weight){ // 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 myHand = "Rock",; - let compChoice = 0; - let scoreboard = 0; //Rules - Computers "choice" -//.00 - .33 : Rock -//.33 - .66 : Paper -//.66 - .99 : Scissors +//.00 - .33 : Rock (4) +//.33 - .66 : Paper(5) +//.66 - .99 : Scissors(6) + function rps(myHand){ - let compChoice = math.random(); + let compChoice = 0; + compChoice = Math.random(); let myChoice = myHand.length; - if (compChoice >= 0 && compChoice < .33) - scoreboard = myChoice - compChoice; - console.log(myChoice); - - + if (myChoice ===6){ + if (compChoice >= 0 && compChoice < .33){ + return "Scissors does not beat Rock! You lose!" + } + else { + return "You win1!" + } + } + else if (myChoice ===4){ + if (compChoice >= .33 && compChoice < .66){ + return "Rock does not beat Paper! You lose!" + } + else { + return "You win2!" + } + } + else{ + if (compChoice >= .66 && compChoice < 1){ + console.log(" Paper does not beat Scissors! You lose!") + } + else { + console.log ("You win3!") + } + } } +console.log(rps("Rock")); + + From 89363406b39e761b9e6ffc7c6b23326785c31248 Mon Sep 17 00:00:00 2001 From: Seth MacPherson Date: Fri, 21 Aug 2020 19:02:49 -0700 Subject: [PATCH 7/9] Answered Task 4 and 5 VERY easily! Kept it DRY. --- index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 5a5b4a0a6..be31d1942 100644 --- a/index.js +++ b/index.js @@ -175,13 +175,20 @@ console.log(rps("Rock")); /************************************************************** Task 5 **************************************************************/ //Metric Converter //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles - - +function mericanize (kM){ + return ( kM * 0.621371 ); +} +console.log(mericanize(300)); +//186.4113 is correct for 300 //b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters - +function fancyTea (feet){ + return ( feet * 30.48 ); + } + console.log(fancyTea(300)); + //9144 is correct for 300 @@ -196,7 +203,7 @@ console.log(rps("Rock")); /************************************************************** Task 7 **************************************************************/ //Grade Calculator -//write a javaScript program that takes a mark out of 100 and returns a corisponding letter grade +//write a javaScript program that takes `a mark out of 100 and returns a corisponding letter grade //90s should be A //80s should be B //70s should be Cs From d07994554daefadb6f360e60507fc03aa8bfad80 Mon Sep 17 00:00:00 2001 From: Seth MacPherson Date: Fri, 21 Aug 2020 21:18:26 -0700 Subject: [PATCH 8/9] Task 6 complete --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index be31d1942..4bbc1e69e 100644 --- a/index.js +++ b/index.js @@ -196,9 +196,14 @@ function fancyTea (feet){ // 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(startBottle){ + let nextBottle = startBottle - 1; + console.log(startBottle, " bottles of soda on the wall.") + console.log(startBottle, " bottles of soda on the wall.") + console.log("Take one down pass it around " , nextBottle , " bottles of soda on the wall.") +} +annoyingSong(21); /************************************************************** Task 7 **************************************************************/ From bc7dd8a15c970a474dd9540721b8b3dd911761da Mon Sep 17 00:00:00 2001 From: Seth MacPherson Date: Fri, 21 Aug 2020 22:18:10 -0700 Subject: [PATCH 9/9] Brought my RPS code down to stretch, rest of assignment complete. Will work more tomorrow if I have time --- index.js | 205 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 177 insertions(+), 28 deletions(-) diff --git a/index.js b/index.js index 4bbc1e69e..755ebe2f1 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ let votingAge = 18; -// all of my work was done on repl.it because I couldnt figure out how to do it in VSC. +// I started this assignment on repl.it and then moved to here after I solved some issues with VSC. if (votingAge >= 18) { console.log(true); } @@ -134,41 +134,132 @@ console.log(foodWeight(1, 15)); //Rules - Computers "choice" //.00 - .33 : Rock (4) //.33 - .66 : Paper(5) -//.66 - .99 : Scissors(6) - +//.66 - .99 : Scissors(6) function rps(myHand){ - let compChoice = 0; - compChoice = Math.random(); + let compChoice = Math.random(); let myChoice = myHand.length; - if (myChoice ===6){ - if (compChoice >= 0 && compChoice < .33){ - return "Scissors does not beat Rock! You lose!" - } - else { - return "You win1!" - } - } - else if (myChoice ===4){ - if (compChoice >= .33 && compChoice < .66){ - return "Rock does not beat Paper! You lose!" - } - else { - return "You win2!" - } + if (compChoice <= .33){ + compChoice = 4; + console.log(compChoice); } - else{ - if (compChoice >= .66 && compChoice < 1){ - console.log(" Paper does not beat Scissors! You lose!") - } - else { - console.log ("You win3!") + else if (compChoice <= .66){ + compChoice = 5; + console.log(compChoice); } - } + else { + compChoice = 6; + console.log(compChoice); + } + if (myChoice === 4 && compChoice === 6){ + return "You win! Rock beats Scissors." + } + else if (myChoice === 5 && compChoice === 4){ + return "You win! Paper beats Rock." + } + else if (myChoice === 6 && compChoice === 5){ + return "You win! Scissors beats Paper" + } + else{ + return "You did not beat your opponent. Please try again." + } } console.log(rps("Rock")); +//See my failures! :D + +// Bad RPS code +// function rps(myHand){ +// let compChoice = Math.random; +// let myChoice = myHand.length; +// if (compChoice <= .33){ +// compChoice = 4; +// } +// else if (compChoice <= .66){ +// compChoice = 5; +// } +// else { +// compChoice = 6; +// } +// if (myChoice = 4){ +// if (compChoice =6){ +// return "You win - Rock beats Scissors"; +// } +// else if (compChoice =4){ +// return "Draw - Choose something original"; +// } +// else { +// return "You lose - Paper beats Rock"; +// } +// } +// else if (myChoice = 5){ +// if (compChoice = 4){ +// return "You win - Paper beats Rock"; +// } +// else if (compChoice = 5){ +// return "Draw - Choose something original"; +// } +// else{ +// return "You lose - Scissors beats Paper"; +// } +// } +// else { +// if (compChoice = 5){ +// return "You win - Scissors beats Paper"; +// } +// else if (compChoice){ +// return "Draw - Choose something original"; +// } +// else{ +// return "You lose - Rock beats Scissors"; +// } +// } +// } +// console.log(rps("Rock")) + + +// OLD RPS CODE + + + +// function rps(myHand){ +// let compChoice = 0; +// compChoice = Math.random(); +// let myChoice = myHand.length; +// if (myChoice ===6){ +// if (compChoice >= 0 && compChoice < .33){ +// return "Scissors does not beat Rock! You lose!" +// } +// else { +// return "You win1!" +// } +// } +// else if (myChoice ===4){ +// if (compChoice >= .33 && compChoice < .66){ +// return "Rock does not beat Paper! You lose!" +// } +// else { +// return "You win2!" +// } +// } +// else{ +// if (compChoice >= .66 && compChoice < 1){ +// console.log(" Paper does not beat Scissors! You lose!") +// } +// else { +// console.log ("You win3!") +// } +// } +// } +// console.log(rps("Rock")); + + + + + + + @@ -214,7 +305,25 @@ annoyingSong(21); //70s should be Cs //60s should be D //and anything below 60 should be F - + +function gradeCalc (score){ + if (score >= 90){ + return ("A"); + } + else if (score >= 80){ + return ("B"); + } + else if (score >= 70){ + return ("C") + } + else if (score >= 60){ + return ("D") + } + else { + return ("F") + } +} +console.log(gradeCalc(81)); @@ -231,3 +340,43 @@ annoyingSong(21); /************************************************************** Stretch **************************************************************/ //Take Rock, Paper, Sissors further //update your rock papers sissors code below to take a prompt from a user using the window object + +function getHand (){ + let myHand = prompt("Please enter your choice for Rock, Paper, Scissors","NO"); + +} + + + + + +function rps(myHand){ + let compChoice = Math.random(); + let myChoice = myHand.length; + if (compChoice <= .33){ + compChoice = 4; + console.log(compChoice); + } + else if (compChoice <= .66){ + compChoice = 5; + console.log(compChoice); + } + else { + compChoice = 6; + console.log(compChoice); + } + if (myChoice === 4 && compChoice === 6){ + return "You win! Rock beats Scissors." + } + else if (myChoice === 5 && compChoice === 4){ + return "You win! Paper beats Rock." + } + else if (myChoice === 6 && compChoice === 5){ + return "You win! Scissors beats Paper" + } + else{ + return "You did not beat your opponent. Please try again." + } +} +console.log( "You chose: " + getHand()); +console.log( getHand() + rps() ); \ No newline at end of file