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
93 changes: 86 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,55 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)

let votingAge = age;


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 height = 0;

if(height <= 3ft){
height = height + 1;
}else{
height = height;
};



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

Number("1999");
or
stringToNumber = +"1999";




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

function multiply(a, b) {
return a * b;
};
multiply(5, 4);




/************************************************************** 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(age){
if(age > 19) {
console.log("Too old to be a dog!")
}else if (age >= 1 && age <= 19) {
age = age * 7;
console.log("You are " + age + " dog years old.");
}}
dogYears();



Expand All @@ -49,6 +71,34 @@

// 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 dogFeeder(ageInMonths, weight){
let feed = 0;
if(ageInMonths > 12 && weight == 5)
{
feed = weight * 0.05;
console.log("Feed " + feed + " pounds in a day.");
}
else if(ageInMonths > 12 && weight > 5 || weight <= 10){
feed = weight * 0.04;
console.log("Feed " + feed + " pounds in a day.");
}else if(ageInMonths > 12 && weight > 10 || weight <= 15){
feed = weight * 0.03;
console.log("Feed " + feed + " pounds in a day");
}else if(ageInMonths > 12 && weight > 15){
feed = weight * 0.02;
console.log("Feed " + feed + " pounds in a day");
}else if(weight < 5 && ageInMonths >= 2 || ageInMonths > 4){
feed = weight * 0.1;
console.log("Feed " + feed + " pounds in a day");
}else if(ageInMonths >= 4 || ageInMonths >= 7 && weight < 5){
feed = weight * 0.05;
console.log("Feed " + feed + " pounds in a day");
}else if( ageInMonths > 7 || ageInMonths < 12 && weight < 5){
feed = weight * 0.04;
console.log("Feed " + feed + " pounds in a day");
}
}
dogFeeder(6, 4);



Expand All @@ -59,20 +109,41 @@
// 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

function game(str){
let random = Math.random();
if(str == "Scissors" || str == "scissors" && random < .3){
console.log("You won!")
}else if(str == "Paper" || str == "paper" && random >= .3 && random < .6){
console.log("You won!!")
}else if(str == "Rock" || "rock" && random > .6 && random <= .9){
console.log("You won!!!")
}else {
console.log("You Lost")
}
};

game("scissors");



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

function converter(kilo){
kilo = kilo * 0.62137119;
console.log(kilo + " miles");
};
converter(5);




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

function converter(feet){
feet = feet * 30.48;
console.log(feet + " centimeters");
};
converter(5);



Expand All @@ -81,7 +152,15 @@
// 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(bottles){
for(let i = bottles; i > 1; i--){
let left = bottles-- - 1;
let left2 = i;
let left3 = left--;
console.log(left2 + " bottles of soda on the wall, " + left3 + " bottles of soda, take one down pass it around, " + left + " bottles of soda on the wall");
}
};
annoyingSong(10);



Expand Down