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

let votingAge= 18

if (votingAge < 18) {
console.log(false)
} else {
console.log(true)
}


console.log(typeof votingAge)

//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 chocolate='dark';
let taste ='bad';
if(taste==='good'){
chocolate='dark';
}else if (taste==='bad'){
chocolate='milk';
}

console.log(chocolate);



//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
const mult = (a, b) => a * b

function multiply(a, b) {
console.log(a * b)

}


multiply(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){
console.log(7 * age)
}
dogYears(25)


/************************************************************** Task 3 **************************************************************/
Expand All @@ -49,7 +68,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(weight, age){
if (weight <= 5 && age >= 1){
console.log(weight*.05);
}
else if (weight <= 10 && weight >= 6 && age >= 1){
console.log(weight*.04);
}
else if (weight >=15 && weight >= 11 && age >= 1){
console.log(weight*.03);
}
else if (weight > 15 && age >= 1){
console.log(weight*.02);
}
else if (age >= .16 && age <= .33){
console.log(weight*.10);
}
else if (age >= .34 && age <= .58){
console.log(weight*.5);
}
else if (age >= .59 && age <=1){
console.log(weight*.4);
}
else {
console.log('invalid parameters');
}
}

dogFeeder(15,1);



Expand All @@ -60,20 +106,57 @@
// 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 computerChoice = Math.random();

// if (computerChoice <= 0.34){
// computerChoice = 'rock'
// }
// else if (computerChoice <=0.67){
// computerChoice= 'paper'
// }
// else if (computerChoice >= 0.67){
// computerChoice = 'sissors'
// }

// function rockPaperSissors(userChoice, computerChoice){

// if (userChoice === computerChoice){
// console.log('Draw')
// }
// else if (userChoice === 'rock' && computerChoice === 'sissors'){
// console.log('You Win!')
// }
// else if (userChoice === 'paper' && computerChoice === 'rock'){
// console.log('You Win!')
// }
// else {
// console.log('You Lose!')
// }
// }

// rockPaperSissors('rock', computerChoice);


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


function kmToMiles(km){
console.log(km * 0.621371)
}

kmToMiles(5)



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

function ftToCm(ft){
console.log(ft * 30.48)
}

ftToCm(5)



Expand All @@ -84,6 +167,15 @@



function annoyingSong (bottles) {
for (let i=bottles; 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")
}
}

annoyingSong(99)




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

function grades(number){
if (number >= 90) {
console.log('A')
}
else if (number >=80 && number < 90){
console.log('B')
}
else if (number >=70 && number < 80){
console.log('C')
}
else if (number >=60 && number < 70){
console.log('D')
}
else {
console.log('F')
}

}



Expand All @@ -113,6 +224,36 @@
//update your rock papers sissors code below to take a prompt from a user using the window object



let computerChoice = Math.random();

if (computerChoice <= 0.34){
computerChoice = 'rock'
}
else if (computerChoice <=0.67){
computerChoice= 'paper'
}
else if (computerChoice >= 0.67){
computerChoice = 'sissors'
}

function rockPaperSissors(userChoice, computerChoice){

if (userChoice === computerChoice){
console.log('Draw')
}
else if (userChoice === 'rock' && computerChoice === 'sissors'){
console.log('You Win!')
}
else if (userChoice === 'paper' && computerChoice === 'rock'){
console.log('You Win!')
}
else {
console.log('You Lose!')
}
}

let userInput = prompt('Rock, Paper, or Sissors?')

rockPaperSissors(userInput, computerChoice);