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
147 changes: 141 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)
var votingAge=18;
if ( 36>votingAge){
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)

var pizza="cheese";
var soda="pepsi";
if ( soda==="pepsi")
{
pizza="sausage";
}




//Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method
var yearString="1999";
var year=parseInt(yearString)






//Task d: Write a function to multiply a*b
function mult(a,b){
var r= a*b;
return r;

}



Expand All @@ -26,6 +46,10 @@
/************************************************************** 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
funtion dogYears(humanyears){
var r=humanyears*7;
return r;
}



Expand All @@ -48,7 +72,50 @@
// 7 - 12 months 4% of their body weight

// 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(age>=1){
if(weight<5){
var food=weight*.05;
return food;
}
else if(weight<10){
var food=weight*.04;
return food;

}
else if(weight<15){
var food=weight*.03;
return food;

}
else {
var food=weight*.02;
return food;


}
}
else{
if(age<.333){ //.333=4months
var food=weight*.10;
return food;
}
else if(age<.583){//.583=7 months
var food=weight*.05;
return food;

}

else {
var food=weight*.04;
return food;


}
}

}




Expand All @@ -60,20 +127,61 @@
// 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(userChoice){
var computerChoice;
computerChoice=Math.floor(Math.random()*3);
//0=rock 1=paper 2=scissors
if(computerChoice===0){
if(userChoice==="rock"){
return "Draw";
}
else if(userChoice==="paper"){
return "user won"
}else if (userChoice==="scissors"){
return "user lose"
}

}else if(computerChoice===1){
if(userChoice==="rock"){
return "user loss";
}
else if(userChoice==="paper"){
return "draw";
}else if (userChoice==="scissors"){
return "user win";
}


}
else if(computerChoice===2){
if(userChoice==="rock"){
return "user wins";
}
else if(userChoice==="paper"){
return "user loss";
}else if (userChoice==="scissors"){
return "draw";
}

}
}


/************************************************************** 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){
return 0.621371*km;
}



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


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



Expand All @@ -82,7 +190,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 (numberOfBottles){

for(let i=numberOfBottles;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`);
}

}



Expand All @@ -94,6 +208,27 @@
//70s should be Cs
//60s should be D
//and anything below 60 should be F
function gradeCalulator (mark) {
if( mark>=90){
return "A";

}
else if(mark>=80){
return "B";
}
else if(mark>=70){
return "c";
}
else if(mark>=60){
return "D";
}
else {
return "F";
}


}




Expand Down