From 167ba06c4a9fdf31a6b9405c0e2f331526372b56 Mon Sep 17 00:00:00 2001 From: Jennifer Kramer Date: Tue, 8 Sep 2020 18:55:55 -0400 Subject: [PATCH 1/5] added notes to javascript assignment - not completed yet --- .vscode/launch.json | 15 +++++++++++ index.js | 61 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..7a9dfa044 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/index.js b/index.js index 73f240372..3d6bdf5b5 100644 --- a/index.js +++ b/index.js @@ -2,12 +2,23 @@ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) +// const 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 fruit1 = "Apple"; +// let isTasty = "Yum"; +// if(isTasty === "Yum"){ +// fruit1 = "Delicious"; +// }else { +// fruit1 = "Gross"; +// } +// console.log(fruit1) @@ -19,6 +30,10 @@ //Task d: Write a function to multiply a*b +function math(a * b){ + console.log(math(1,2)) +} + @@ -27,8 +42,11 @@ //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 +// function dogYears(age){ +// return Math.pow(age,7); +// } - +// console.log(dogYears(25)); /************************************************************** Task 3 **************************************************************/ @@ -95,9 +113,42 @@ //60s should be D //and anything below 60 should be F - - - +//that takes = function + +// switch (x) { +// case x >= 90; +// let grade = "A"; +// return grade + +// case x >= 80; +// x = "B"; + +// break; +// case x >= 70; +// x = "C" +// break; +// case x >= 60; +// x = "D" +// break; +// case x >= 50; +// x = "F" +// } +// console.log(72); + +// function grades(number) { +// if(numer >= 90){ +// //do something +// } +// } + +// grades(100) + +/* Caveman vs Spaceman + 1. Plan english(native language too!) + 2. Try to solve the problem in your own words + 3. Start coding! Don't over think it or over optimize it at this point + 4. Once it's working, look at some optimizations (in a few weeks!) +*/ /************************************************************** Stretch **************************************************************/ //Create a function that counts the number of vowels within a string. It should handle both capitalized and uncapitalized vowels. From 4e60cb59d2565b2ff98c80b4a71bc6939fb60808 Mon Sep 17 00:00:00 2001 From: Jennifer Kramer Date: Tue, 8 Sep 2020 22:15:52 -0400 Subject: [PATCH 2/5] Have answered up to Task 3 --- index.js | 59 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 3d6bdf5b5..e27cc52de 100644 --- a/index.js +++ b/index.js @@ -1,37 +1,44 @@ /************************************************************** Task 1: Warm-up! **************************************************************/ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) +//declare a variable +//use if else statement +//true if age is greater than 18 +const votingAge = 19; -// const votingAge = 19; - -// if(votingAge > 18){ -// console.log("true"); -// } +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 fruit1 = "Apple"; -// let isTasty = "Yum"; -// if(isTasty === "Yum"){ -// fruit1 = "Delicious"; -// }else { -// fruit1 = "Gross"; -// } -// console.log(fruit1) + var a = 15; + var b = 30; + if (a === 10) { + console.log("True!"); + } else { + console.log("False!"); +} //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method +//Declare a variable "1999" +//Write a console to equal 1999 +var num = "1999"; +console.log(num); //Task d: Write a function to multiply a*b -function math(a * b){ - console.log(math(1,2)) +function Multiply(a, b){ + var a = 2 + var b = 3 + console.log(a * b) } @@ -42,17 +49,30 @@ function math(a * b){ //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 -// function dogYears(age){ -// return Math.pow(age,7); -// } +function dogYears(age){ + return Math.pow(age,7); +} -// console.log(dogYears(25)); +console.log(dogYears(25)); /************************************************************** Task 3 **************************************************************/ //Dog feeder //takes weight in pounds and age in years (note if the dog is a puppy the age will be a decimal) and returns the number of pounds of raw food to feed in a day. + +//takes weight in pounds +//age in years +//returns the number of pounds of raw food to feed in a day + +function hungryDog(age, weight){ + if(age >= 1){ + return weight * 0.05{ + } else if (weight <= 10){ + return weight * 0.04; + } + } + //feeding requirements // adult dogs at least 1 year // up to 5 lbs - 5% of their body weight @@ -70,7 +90,6 @@ function math(a * b){ - /************************************************************** Task 4 **************************************************************/ // Rock, Paper, Sissors // Your function should take a string (either rock paper or sissors) From d533edbb7846be5c885805c77cba327b4489d170 Mon Sep 17 00:00:00 2001 From: Jennifer Kramer Date: Tue, 8 Sep 2020 22:46:26 -0400 Subject: [PATCH 3/5] Completed task 4 to best of ability --- index.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index e27cc52de..49c383455 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,7 @@ if(votingAge > 18){ //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method +// NOTES //Declare a variable "1999" //Write a console to equal 1999 var num = "1999"; @@ -60,19 +61,6 @@ console.log(dogYears(25)); //Dog feeder //takes weight in pounds and age in years (note if the dog is a puppy the age will be a decimal) and returns the number of pounds of raw food to feed in a day. - -//takes weight in pounds -//age in years -//returns the number of pounds of raw food to feed in a day - -function hungryDog(age, weight){ - if(age >= 1){ - return weight * 0.05{ - } else if (weight <= 10){ - return weight * 0.04; - } - } - //feeding requirements // adult dogs at least 1 year // up to 5 lbs - 5% of their body weight @@ -87,17 +75,39 @@ function hungryDog(age, 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 +// NOTES +//Takes weight in pounds +//Age in years (puppy in decimal; dog as integers) +//Returns the number of pounds of raw food to feed in a day + +let age = 1 +let weight = 15 + +function feedTheDog(age, weight){ + if(age >= 1 && weight <= 5){ + return weight * 0.05; + } else if (weight <= 10){ + return weight * 0.04; + } else if (weight <= 15){ + return weight * 0.3; + } else (weight >= 15) + return weight * 0.2; + } + feedTheDog(1, 15); /************************************************************** Task 4 **************************************************************/ // Rock, Paper, Sissors -// Your function should take a string (either rock paper or sissors) +// Your function should take a string (either rock paper or scissors) // it should return you won or you lost based on the rules of the game (you may need to look up the rules if you have not played before) // 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 + + + /************************************************************** Task 5 **************************************************************/ From eb604ca51dc83e315737a507dd03643161250560 Mon Sep 17 00:00:00 2001 From: Jennifer Kramer Date: Wed, 9 Sep 2020 00:27:47 -0400 Subject: [PATCH 4/5] Answered up to task 6 - incomplete --- index.js | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 49c383455..d47fd49c5 100644 --- a/index.js +++ b/index.js @@ -98,14 +98,55 @@ function feedTheDog(age, weight){ /************************************************************** Task 4 **************************************************************/ -// Rock, Paper, Sissors +// Rock, Paper, Scissors // Your function should take a string (either rock paper or scissors) // it should return you won or you lost based on the rules of the game (you may need to look up the rules if you have not played before) // 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 - - +// NOTES +//function is mentioned +//return you won or lost +//use math.random to determine random handSymbols +//equate choice to a number (integer) + //****Rules of the Game***// + //scissors vs. rock = lost + //scissors vs. paper = win + //scissors vs. scissors = draw + //rock vs. scissors = win + //rock vs. paper = lost + //rock vs. rock = draw + //paper vs. scissors = lost + //paper vs. rock = win + //paper vs. paper = draw + +const rock = "r"; +const paper = "p"; +const scissors = "s"; +var random = Math.floor(Math.random() * 60) + 1; + +function handSymbol(rock, paper, scissors){ + if(rock === r){ + return "draw"; + } else if (rock === p){ + return "lost"; + } else if (rock === s){ + return "win"; + } else if (paper === p){ + return "draw"; + } else if (paper === s){ + return "lost"; + } else if (paper === r){ + return "win"; + } else if (scissors === s){ + return "draw"; + } else if (scissors === r){ + return "lost" + } else if (scissors === p){ + return "win" + } +} +console.log(random) @@ -115,12 +156,30 @@ function feedTheDog(age, weight){ //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles +// NOTES +//make 1.60934 kilometers = 1 mile + +// let kilometers = 1.60934 + +// function miles(kilometers){ +// Multiply(miles * 1.60934) +// } + +// console.log(3 * kilometers) + +var kilometers = parseInt(prompt("Please enter kilometers:")); +var miles = kilometers / 1.6; +console.log(miles + " Miles"); + + //b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters - +var feet = parseInt(prompt("Please enter number of feet that you would like to convert:")); +var cm = feet * 30.48; +console.log(cm + " Centimeters"); @@ -128,9 +187,24 @@ function feedTheDog(age, weight){ // 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(){ + var bottles; + var bottlesLeft; + for (i = 99; i >= 1; i--){ + if (i == 1){ + bottles = "bottle"; + bottlesLeft = "No bottles of soda on the wall"; + } else { + bottles = "bottles"; + bottlesLeft = i -1 + "bottles of soda on the wall"; + } console.log(1+ " " + bottles + " of soda on the wall,"); + console.log("Take one down, pass it around,"); + console.log(bottlesLeft); + } +} +console.log(annoyingSong()); /************************************************************** Task 7 **************************************************************/ @@ -142,6 +216,7 @@ function feedTheDog(age, weight){ //60s should be D //and anything below 60 should be F +// NOTES //that takes = function // switch (x) { @@ -193,6 +268,3 @@ function feedTheDog(age, weight){ //update your rock papers sissors code below to take a prompt from a user using the window object - - - From d350e4ca682864c62d3574da25889c1e4f86ce64 Mon Sep 17 00:00:00 2001 From: Jennifer Kramer Date: Wed, 9 Sep 2020 10:57:24 -0400 Subject: [PATCH 5/5] completed javascript assignment --- index.js | 67 +++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/index.js b/index.js index d47fd49c5..2f55772a0 100644 --- a/index.js +++ b/index.js @@ -162,22 +162,20 @@ console.log(random) // let kilometers = 1.60934 // function miles(kilometers){ -// Multiply(miles * 1.60934) +// Divide(miles / 1.60934) // } -// console.log(3 * kilometers) +// console.log(3 / kilometers) -var kilometers = parseInt(prompt("Please enter kilometers:")); +var kilometers = parseInt(prompt("Please enter amount of kilometers:")); var miles = kilometers / 1.6; console.log(miles + " Miles"); - - //b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters -var feet = parseInt(prompt("Please enter number of feet that you would like to convert:")); +var feet = parseInt(prompt("Please enter amount of feet that you would like to convert:")); var cm = feet * 30.48; console.log(cm + " Centimeters"); @@ -212,41 +210,40 @@ console.log(annoyingSong()); //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 +//70s should be C //60s should be D //and anything below 60 should be F // NOTES //that takes = function +function myGrade(x){ + let grade; + switch (x) { + case x >= 90: + grade = "A"; + return grade + + case x >= 80: + grade = "B"; + return grade + + case x >= 70: + grade = "C"; + return grade + + case x >= 60: + grade = "D"; + return grade + + case x < 59: + grade = "F"; + return grade + } + return grade +} +console.log(myGrade(87)) -// switch (x) { -// case x >= 90; -// let grade = "A"; -// return grade - -// case x >= 80; -// x = "B"; - -// break; -// case x >= 70; -// x = "C" -// break; -// case x >= 60; -// x = "D" -// break; -// case x >= 50; -// x = "F" -// } -// console.log(72); - -// function grades(number) { -// if(numer >= 90){ -// //do something -// } -// } - -// grades(100) - +// NOTES /* Caveman vs Spaceman 1. Plan english(native language too!) 2. Try to solve the problem in your own words