Skip to content
107 changes: 88 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,54 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)

age= 29


let votingAge
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)

let weather = "forecast";
let feeling = "happy";

if(feeling = "happy"){
weather = "sunny";
}


console.log(weather);

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


console.log(Number("1999"))



//Task d: Write a function to multiply a*b

let a= 5
let b= 9
function multiply(a,b){
console.log(a*b);
}


multiply(a,b);




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





function dogyears(human,) {
if(human > 0)
return human * 7
}
console.log(dogyears (29));
/************************************************************** 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.
Expand All @@ -49,9 +67,25 @@

// 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 feeder(age, weight) {
if(age >= 1 && weight <= 5) {
return weight * .05
}else if (age >=1 && weight <=10) {
return weight * .04
}else if (age >=1 && weight <=15) {
return weight * .03
}else if (age >=1 && weight >15) {
return weight * .02
}else if (age >= .167 && age < .33) {
return weight * .10
}else if (age >= .33 && age < .583) {
return weight * .05
}else if (age >= .583 && age <1) {
return weight * .04
}
}

console.log (feeder(1, 15));

/************************************************************** Task 4 **************************************************************/
// Rock, Paper, Sissors
Expand All @@ -60,20 +94,40 @@
// 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

for (let i = 0; i<5; i++){

var rockPapScis = Math.round(Math.random())
if (rockPapScis === 1) {
console.log ("win");
}
if (rockPapScis === 0) {
console.log ("lose");
}

}



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



function miles(km){
if (km > 0){
return km * 0.621
}
}
console.log (miles(5));


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


function cm(ft){
if (ft > 0) {
return ft * 30.48
}
}
console.log (cm(2))



Expand All @@ -82,6 +136,13 @@
// 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 bottles = 99; bottles > 0; bottles--) {
console.log (bottles);
}
}





Expand All @@ -95,8 +156,20 @@
//60s should be D
//and anything below 60 should be F



function grades(percent){
if (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(grades(83));


/************************************************************** Stretch **************************************************************/
Expand All @@ -112,7 +185,3 @@
//Take Rock, Paper, Sissors further
//update your rock papers sissors code below to take a prompt from a user using the window object