Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 106 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//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);
}else {
console.log(false)
}




//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)



//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 car1 = "Lambo";
let isFast = "Yes";

//Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method
if(isFast === "Yes"){
car1 = "Cool Car";
}else {
car1 = "Laaaaame";
}

console.log(car1);

//Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method


const integer = Number("1999");
console.log(integer);

//Task d: Write a function to multiply a*b
function multiply(a, b){
return a * b
}

console.log(multiply(10,5));



Expand All @@ -27,14 +46,20 @@
//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 ageInDogYears(myAge, dogRatio){
return myAge * 7
}

console.log(ageInDogYears(10));



/************************************************************** 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.

// 1,2,3,4

//feeding requirements
// adult dogs at least 1 year
// up to 5 lbs - 5% of their body weight
Expand All @@ -49,7 +74,24 @@

// 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 hungryDog(weight, age){
if(age >= 12 && weight <=5){
return weight * 0.05
} else if(age >= 12 && weight <= 10){
return weight * 0.04
} else if(age >= 12 && weight <= 15){
return weight * 0.03
} else if(age >= 12 && weight > 15){
return weight * 0.02
} else if(age >= 2 && age < 4){
return weight * 0.1
} else if(age >= 4 && age < 7){
return weight * 0.05
} else if(age <= 7 && age < 12){
return weight * 0.04
}
}
console.log(hungryDog(15, 12));



Expand All @@ -59,21 +101,51 @@
// 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



let play=["rock", "paper", "scissors"];
let random=Math.floor(Math.random()* play.length);
let opponent=play[random];

console.log(opponent);

function choice(game){
if (game==="rock" && opponent==="scissors"){
return "you won"
}
else if (game ==="rock" && opponent==="paper"){
return "you lost"
}
else if (game===opponent){
return "you tied"
}
else if (game==="paper" && opponent==="rock"){
return "you won"
}
else if (game==="paper" && opponent==="scissors"){
return "you lost"
}
else if (game==="scissors" && opponent==="rock"){
return "you lost"
}
else if (game==="scissors" && opponent==="paper"){
return "you won"
}
}

console.log(choice("scissors"))

/************************************************************** Task 5 **************************************************************/
//Metric Converter
//a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles


const km2Miles = distance => distance * .621371
console.log(km2Miles(2))



//b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters


const ft2CM = length => length * 30.48
console.log(ft2CM(3))



Expand All @@ -82,9 +154,14 @@
// 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 (bottles){

for(let i = bottles; i >= 1; 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(5)

/************************************************************** Task 7 **************************************************************/
//Grade Calculator
Expand All @@ -95,7 +172,25 @@
//60s should be D
//and anything below 60 should be F


function grade(percent){
if (percent <=100 && percent >=90){
return "A"
}
else if (percent >= 80){
return "B"
}
else if (percent >= 70){
return "C"
}
else if (percent >= 60){
return "D"
}
else if (percent < 60){
return "F"
}
}

console.log(grade(74))



Expand Down