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

let votingAge = 22;


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 thisIsVar = 19;
let notAnotherVar = 6;

if(thisIsVar < notAnotherVar) {
thisIsVar = false;
};

// console.log(thisIsVar);


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

const str = "1999";

// console.log(Number(str))



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

function multi(a,b) {
return a * b;
};


// console.log(multi(1, 2))


/************************************************************** 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) {
return ageInDogYears = age * 7;
};


// console.log(dogYears(30));


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

//feeding requirements
// feeding requirements
// adult dogs at least 1 year
// up to 5 lbs - 5% of their body weight
// 6 - 10 lbs - 4% of their body weight
Expand All @@ -51,6 +68,25 @@



function dogFeeder(weight, age) {
if(age >= 1 && weight <= 5) {
return weight * 0.05;
} else if(age >= 1 && weight >= 6 && weight <= 10){
return weight * 0.04;
} else if(age >= 1 && weight >= 11 && weight <= 15){
return weight * 0.03;
} else if(age >= 1 && weight < 15){
return weight * 0.02;
} else if(age < .75 && age >= 0.583){
return weight * 0.04;
} else if(age < .5 && age >= 0.333){
return weight * 0.05;
} else if(age < .33){
return weight * 0.10;
}
};

// console.log(dogFeeder(16, 1));


/************************************************************** Task 4 **************************************************************/
Expand All @@ -60,20 +96,59 @@
// 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


const paper = 0;
const scissors = 1;
const rock = 2;
let result;

function compyPick(num){
return Math.floor(Math.random() *(num));
}

// console.log(compyPick(3));

function game(choice, compyPick) {
let cPick = compyPick(3);
if(choice == 0 && cPick == 2) {
return result = 'You win';
} else if(choice == 2 && cPick == 0) {
return result = 'You lose';
} else if(choice === cPick) {
return result = 'It\'s a draw!';
} else if(choice > cPick) {
return result = 'You win!';
} else if (choice < cPick) {
return result = 'You lose!';
}
};

// console.log(game(paper, compyPick));


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


let km;

function convertKM(km) {
return km*0.621371;
}

// console.log(convertKM(24));


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


let feet;

function convertFeet(feet) {
return feet*30.48;
}

// console.log(convertFeet(18));



Expand All @@ -82,8 +157,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(num){
for(let i = num; i > 0 ; 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.')
}
}


// console.log(annoyingSong(100))


/************************************************************** Task 7 **************************************************************/
Expand All @@ -94,7 +174,25 @@
//70s should be Cs
//60s should be D
//and anything below 60 should be F


let grade;

function grades(grade){
let MyResult;
if (grade >= 90) {
return myResult = 'A';
} else if(grade >= 80) {
return MyResult = 'B';
} else if(grade >= 70){
return MyResult = 'C';
} else if(grade >= 60){
return MyResult = 'D';
} else if(grade <= 59){
return MyResult = 'F';
}
}

// console.log(grades(10));



Expand All @@ -104,15 +202,9 @@
// Hint - you may need to study tomorrow's traning kit on arrays
// try looking up the .includes() method




/[A-Za-z]g/

/************************************************************** Stretch **************************************************************/
//Take Rock, Paper, Sissors further
//update your rock papers sissors code below to take a prompt from a user using the window object