From 0f95e2a5e4e537c0ff26faf21fba063c4d01437a Mon Sep 17 00:00:00 2001 From: Angela Engel Date: Fri, 18 Sep 2020 22:09:59 -0600 Subject: [PATCH 1/9] Task 1 A and B --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 73f240372..89f6c2106 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,15 @@ /************************************************************** Task 1: Warm-up! **************************************************************/ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) +var votingAge = 18 - - +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) +var name = "Anthony" - - +var name = "Tony" //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method From ddddb7323d54f857d0e16b5d3d0b61deb8191711 Mon Sep 17 00:00:00 2001 From: Angela Engel Date: Tue, 22 Sep 2020 16:20:13 -0600 Subject: [PATCH 2/9] tasks 1, 2, 3, 5, 6 done --- index.js | 70 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 89f6c2106..8196a9365 100644 --- a/index.js +++ b/index.js @@ -1,25 +1,38 @@ /************************************************************** Task 1: Warm-up! **************************************************************/ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) -var votingAge = 18 +let votingAge = 18 -if (votingAge > 18) {console.log("true")} +if (votingAge => 18) { + console.log(true) +} else { + console.log('Not old enough') +} //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) -var name = "Anthony" +let a = 1 +let b = 2 -var name = "Tony" //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method - +Number("1999") +console.log(Number) //Task d: Write a function to multiply a*b +let a = 2 +let b = 4 +function mulTwoNums (a, b) { + return a * b; + } + +console.log(mulTwoNums(2,4)) + @@ -27,7 +40,10 @@ var name = "Tony" //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 num1 = 32 +function mulTwoNums (a,b) { + return (num1 * 7) +} @@ -49,9 +65,28 @@ var name = "Tony" // 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 hoMuchFood(){ + let weight = prompt("How many pounds does your dog weigh?"); + let age = prompt("How old is your dog? Whole number if over 1 year. If puppy round to nearest quarter year, .25 for 3 months, .5 for six months, .75 for 9 months."); +} + +if (weight <= 5 && age >= 1){ + console.log('Your dog weighs' + weight + 'pounds!' + 'Dog should eat' + weight*.05 + 'pounds of food every day!') +} else if (weight <= 10 && age >= 1){ + console.log('Your dog weighs' + weight + 'pounds!' + 'Dog should eat' + weight*.04 + 'pounds of food every day!') +} else if(weight <= 15 && age >= 1){ + console.log('Your dog weighs' + weight + 'pounds!' + 'Dog should eat' + weight*.03 + 'pounds of food every day!') +} else if (weight >= 15 && age >= 1){ + console.log('Your dog weighs' + weight + 'pounds!' + 'Dog should eat' + weight*.02 + 'pounds of food every day!') +} else if (weight >= 5 && age <= .25){ + console.log('Your dog weighs' + weight + 'pounds!' + 'Dog should eat' + weight*.10 + 'pounds of food every day!') +} else if (weight >= 5 && age <= .5){ + console.log('Your dog weighs' + weight + 'pounds!' + 'Dog should eat' + weight*.05 + 'pounds of food every day!') +} else if (weight >= 5 && age <= .75){ + console.log('Your dog weighs' + weight + 'pounds!' + 'Dog should eat' + weight*.04 + 'pounds of food every day!') +} + +console.log(howMuchFood()) /************************************************************** Task 4 **************************************************************/ // Rock, Paper, Sissors @@ -67,14 +102,19 @@ var name = "Tony" //Metric Converter //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles +function KmToMiles(kn){ + return km * 1.609; +} - - +console.log(KmToMiles(2)) //b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters +function feetToCm(ft){ + return ft * 30.48; +} - +console.log(feetToCm(2)) /************************************************************** Task 6 **************************************************************/ @@ -83,7 +123,11 @@ var name = "Tony" // 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 = bottles; i > 0; i--){ + console.log(`${i} of soda on the wall, ${i} of soda! Take one down, pass it around. ${i - 1} bottles of soda on the wall!`) + } +} /************************************************************** Task 7 **************************************************************/ From bf0418a3cad4ae1652bd1eb287af1ff7a6ba84c9 Mon Sep 17 00:00:00 2001 From: Angela Engel Date: Tue, 22 Sep 2020 16:50:23 -0600 Subject: [PATCH 3/9] Task 4 done --- index.js | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8196a9365..69379204c 100644 --- a/index.js +++ b/index.js @@ -95,6 +95,46 @@ console.log(howMuchFood()) // 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 +const rock = 0 +const paper = 1 +const scissors = 2 + +let player1 = Math.floor(Math.random() * 3) +let player2 = Math.floor(Math.random() * 3) + +if (player1 === 0){ + return 'rock'; +} else if (player1 === 1){ + return 'paper'; +} else if (player1 === 2){ + return 'scissors'; +} + +if (player2 === 0){ + return 'rock'; +} else if (player2 === 1){ + return 'paper'; +} else if (player2 === 2){ + return 'scissors'; +} + +if (player1 === player2){ + return 'Tie'; +} else if (player1 === 0 && player2 === 1){ + return 'Paper wins'; +} else if (player1 === 0 && player2 === 2){ + return 'Rock wins'; +} else if (player1 === 1 && player2 === 0){ + return 'Paper wins'; +} else if (player1 === 1 && player2 === 2){ + return 'Scissors wins'; +} else if (player1 === 2 && player2 === 0){ + return 'Rock wins'; +} else if (player1 === 2 && player2 === 1){ + return 'Scissors wins'; +} + +console.log(player1,player2) @@ -138,7 +178,8 @@ function annoyingSong(bottles) { //70s should be Cs //60s should be D //and anything below 60 should be F - + + From f5fd802b27fe998e36fb0e073fdaf0b9d3124ebb Mon Sep 17 00:00:00 2001 From: Angela Engel Date: Tue, 22 Sep 2020 17:02:57 -0600 Subject: [PATCH 4/9] Task 7 done --- index.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 69379204c..362f15136 100644 --- a/index.js +++ b/index.js @@ -179,9 +179,21 @@ function annoyingSong(bottles) { //60s should be D //and anything below 60 should be F +function gradeCalc(score){ + if (score < 60){ + return 'F'; + } else if (score >= 60 && < 70){ + return 'D'; + } else if (score >= 70 && < 80){ + return 'C'; + } else if (score >= 80 && < 90){ + return 'B'; + } else if (score >= 90){ + return 'A'; + } +} - - + console.log(gradeCalc(82)) /************************************************************** Stretch **************************************************************/ From 90128b6c9fae89c123bb153c4a56346cb79ec378 Mon Sep 17 00:00:00 2001 From: Angela Engel Date: Tue, 22 Sep 2020 17:21:16 -0600 Subject: [PATCH 5/9] fixed problem --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 362f15136..5dda77966 100644 --- a/index.js +++ b/index.js @@ -182,11 +182,11 @@ function annoyingSong(bottles) { function gradeCalc(score){ if (score < 60){ return 'F'; - } else if (score >= 60 && < 70){ + } else if (score >= 60 && score < 70){ return 'D'; - } else if (score >= 70 && < 80){ + } else if (score >= 70 && score < 80){ return 'C'; - } else if (score >= 80 && < 90){ + } else if (score >= 80 && score < 90){ return 'B'; } else if (score >= 90){ return 'A'; From cf3a0192d8518b44de1f4bc833efb75fb8aab9c0 Mon Sep 17 00:00:00 2001 From: Angela Engel Date: Tue, 22 Sep 2020 19:50:40 -0600 Subject: [PATCH 6/9] adjustments --- index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 5dda77966..c2a05fed7 100644 --- a/index.js +++ b/index.js @@ -12,13 +12,16 @@ if (votingAge => 18) { //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 a = 1 -let b = 2 +let b = 1 +if (a === b){ + b = 2 +} //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method -Number("1999") -console.log(Number) +let num = Number("1999") +console.log(num) @@ -41,8 +44,8 @@ console.log(mulTwoNums(2,4)) //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 num1 = 32 -function mulTwoNums (a,b) { - return (num1 * 7) +function mulTwoNums (a) { + return (a * 7) } From 61ce9c8c300cd33ef7aa83421d5a7a8a9ff7d799 Mon Sep 17 00:00:00 2001 From: Angela Engel Date: Sun, 15 Nov 2020 16:34:46 -0700 Subject: [PATCH 7/9] fixed problems --- index.js | 87 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index c2a05fed7..8d695d7ac 100644 --- a/index.js +++ b/index.js @@ -27,11 +27,11 @@ console.log(num) //Task d: Write a function to multiply a*b -let a = 2 -let b = 4 +let c = 2 +let d = 4 -function mulTwoNums (a, b) { - return a * b; +function mulTwoNums (c, d) { + return c * d; } console.log(mulTwoNums(2,4)) @@ -67,11 +67,14 @@ function mulTwoNums (a) { // 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 hoMuchFood(){ - let weight = prompt("How many pounds does your dog weigh?"); + +let weight = prompt("How many pounds does your dog weigh?"); let age = prompt("How old is your dog? Whole number if over 1 year. If puppy round to nearest quarter year, .25 for 3 months, .5 for six months, .75 for 9 months."); -} + + + +function howMuchFood() { + if (weight <= 5 && age >= 1){ console.log('Your dog weighs' + weight + 'pounds!' + 'Dog should eat' + weight*.05 + 'pounds of food every day!') @@ -88,9 +91,9 @@ if (weight <= 5 && age >= 1){ } else if (weight >= 5 && age <= .75){ console.log('Your dog weighs' + weight + 'pounds!' + 'Dog should eat' + weight*.04 + 'pounds of food every day!') } - -console.log(howMuchFood()) - +} + +console.log(howMuchFood()) /************************************************************** Task 4 **************************************************************/ // Rock, Paper, Sissors // Your function should take a string (either rock paper or sissors) @@ -102,50 +105,61 @@ const rock = 0 const paper = 1 const scissors = 2 -let player1 = Math.floor(Math.random() * 3) -let player2 = Math.floor(Math.random() * 3) +const player1 = prompt("rock, paper, scissors") +const computer = Math.floor(Math.random() * 3) -if (player1 === 0){ - return 'rock'; -} else if (player1 === 1){ - return 'paper'; -} else if (player1 === 2){ - return 'scissors'; -} +function game(player1, computer){ + //player1 = prompt("rock, paper, scissors"); + //computer = Math.floor(Math.random() * 3) + + + +//if (player1 === 0){ + // return 'rock'; +//} else if (player1 === 1){ + // return 'paper'; +//} else if (player1 === 2){ + // return 'scissors'; +//} -if (player2 === 0){ +if (computer === 0){ return 'rock'; -} else if (player2 === 1){ +} else if (computer === 1){ return 'paper'; -} else if (player2 === 2){ +} else if (computer === 2){ return 'scissors'; } +} + +console.log(game(player1, computer)) + +function playGame(game){ -if (player1 === player2){ +if (player1 === computer){ return 'Tie'; -} else if (player1 === 0 && player2 === 1){ +} else if (player1 === 0 && computer === 1){ return 'Paper wins'; -} else if (player1 === 0 && player2 === 2){ +} else if (player1 === 0 && computer === 2){ return 'Rock wins'; -} else if (player1 === 1 && player2 === 0){ +} else if (player1 === 1 && computer === 0){ return 'Paper wins'; -} else if (player1 === 1 && player2 === 2){ +} else if (player1 === 1 && computer === 2){ return 'Scissors wins'; -} else if (player1 === 2 && player2 === 0){ +} else if (player1 === 2 && computer === 0){ return 'Rock wins'; -} else if (player1 === 2 && player2 === 1){ +} else if (player1 === 2 && computer === 1){ return 'Scissors wins'; } +} -console.log(player1,player2) - +console.log(playGame(game(player1, computer))) /************************************************************** Task 5 **************************************************************/ //Metric Converter //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles -function KmToMiles(kn){ +function KmToMiles(km){ return km * 1.609; } @@ -166,12 +180,13 @@ console.log(feetToCm(2)) // 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 = bottles; i > 0; i--){ - console.log(`${i} of soda on the wall, ${i} of soda! Take one down, pass it around. ${i - 1} bottles of soda on the wall!`) +function annoyingSong(i) { + for (let i = 15; i > 0; i--){ + return `${i} of soda on the wall, ${i} of soda! Take one down, pass it around. ${i - 1} bottles of soda on the wall!` } } +console.log(annoyingSong(15)) /************************************************************** Task 7 **************************************************************/ //Grade Calculator From a17a31ffb857e9530f8b3dfc3749fac3bf7b58f1 Mon Sep 17 00:00:00 2001 From: Angela Engel Date: Sun, 15 Nov 2020 16:37:28 -0700 Subject: [PATCH 8/9] additional changes --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 8d695d7ac..85d43e4a3 100644 --- a/index.js +++ b/index.js @@ -109,8 +109,7 @@ const player1 = prompt("rock, paper, scissors") const computer = Math.floor(Math.random() * 3) function game(player1, computer){ - //player1 = prompt("rock, paper, scissors"); - //computer = Math.floor(Math.random() * 3) + From ce679f54ff54473325e4168c111cd2a0f8a7ba77 Mon Sep 17 00:00:00 2001 From: Angela Engel Date: Sun, 15 Nov 2020 16:39:07 -0700 Subject: [PATCH 9/9] fixed most issues --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 85d43e4a3..1c80cabf7 100644 --- a/index.js +++ b/index.js @@ -111,8 +111,6 @@ const computer = Math.floor(Math.random() * 3) function game(player1, computer){ - - //if (player1 === 0){ // return 'rock'; //} else if (player1 === 1){ @@ -179,13 +177,13 @@ console.log(feetToCm(2)) // 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(i) { +function annoyingSong() { for (let i = 15; i > 0; i--){ return `${i} of soda on the wall, ${i} of soda! Take one down, pass it around. ${i - 1} bottles of soda on the wall!` } } -console.log(annoyingSong(15)) +console.log(annoyingSong()) /************************************************************** Task 7 **************************************************************/ //Grade Calculator