diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..a22dd5b40 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // 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..06b672ad6 100644 --- a/index.js +++ b/index.js @@ -1,24 +1,42 @@ /************************************************************** Task 1: Warm-up! **************************************************************/ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) +let Age = 44; +if (Age>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 theVariable = 'False'; + if (true) { + theVariable = 'True'; + } //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method +var a = "1999"; + var b = parseInt(a); +console.log(b); //Task d: Write a function to multiply a*b +var a = 3; +var b = 2; +var c = a * b; +console.log(c) @@ -26,7 +44,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 myAge = 44; +let myAgeInDogYears = myAge * 7; +console.log(myAgeInDogYears) @@ -49,9 +69,30 @@ // 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 - - - +var weight = prompt("dog's weight"); +var age = prompt("dog's age (for puppies use fraction of year)"); +if (age>=1&&weight<=5) { + feeding = (weight * .05); +} +else if (age>=1&&weight<=10) { + feeding = (weight * .04); +} +else if (age>=1&&weight<=15) { + feeding = (weight * .03); +} +else if (age>=1&&weight>15) { + feeding = (weight * .02); +} +else if (age<=.33) { + feeding = (weight * .1); +} +else if (age>=.58) { + feeding = (weight * .05); +} +else if (age<=.99) { + feeding = (weight * .04); +} +console.log(feeding + " lbs."); /************************************************************** Task 4 **************************************************************/ // Rock, Paper, Sissors @@ -60,20 +101,63 @@ // 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 - +var userChoice = prompt("Rock, paper or scissors?"); +var computerChoice = Math.random(); +if (computerChoice < 0.34) { + computerChoice = "rock"; +} else if(computerChoice <= 0.67) { + computerChoice = "paper"; +} else { + computerChoice = "scissors"; +} +var compare=function(choice1,choice2){ + if(choice1===choice2){ + return "tie!"; + } + else if(choice1==="rock"){ + if(choice2==="scissors"){ + return "rock wins" + } + else if(choice2==="paper"){ + return "paper wins"; + } + } + else if(choice1==="paper"){ + if(choice2==="scissors"){ + return "scissors win" + } + else if(choice2==="rock"){ + return "paper wins"; + } + } + else if(choice1==="scissors"){ + if(choice2==="paper"){ + return "scissors win" + } + else if(choice2==="rock"){ + return "rock wins"; + } + } + +} +console.log(compare(userChoice,computerChoice)); /************************************************************** Task 5 **************************************************************/ //Metric Converter //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles - +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")); +var centimeters = feet * 30.48; +console.log(centimeters + " centimeters") @@ -82,7 +166,24 @@ // 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(i+ " " + bottles + " of soda on the wall,"); + console.log(i+ " " + bottles + " of soda,"); + console.log("Take one down, pass it around,"); + console.log(bottlesLeft); + } + + } + console.log(annoyingSong()); @@ -95,7 +196,23 @@ //60s should be D //and anything below 60 should be F - +var score = prompt("what is your score?") + +if(score >= 90) { + alert("your grade is an A"); +} +if(score<=89&&score>=80) { + alert("your grade is a B"); +} +if(score<=79&&score>=70) { + alert("your grade is a C"); +} +if(score<=69&&score>=60) { + alert("your grade is a D"); +} +if(score<60) { + alert("you failed!"); +}