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


const votingAge = 19;
console.log(votingAge > 18);



//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 sodaCans = 'pepsi';
if (sodaCans === 'pepsi'){
let sodaCans = 'Coca Cola';
console.log('Coca Cola is the sweet');
}
else{
let sodaCans = 'pepsi';
}


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


Number("1999");
if ("1999" == 1999){
console.log("Changed that Number");
}



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


function letters(a,b = 1){
return a*b;
}



let c = letters(6,24);
console.log(c);
/************************************************************** 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,dog = 7){
return human*dog;
}
console.log(dogYears(28));


/************************************************************** Task 3 **************************************************************/
Expand All @@ -48,9 +64,48 @@
// 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 answer(suki){
console.log("Dog gets" ,suki, "lbs of food");
}
function adultDog(weight){
if (weight <= 5){
answer(weight*.05);
}
else if (weight <= 10){
answer(weight*.04);
}
else if (weight <= 15){
answer(weight*.03);
}
else if (weight <= 15){
answer(weight*.02);
}
else{
answer(weight*.02);
}
}

function puppy(age,weight){
if (age >= .166666 && age <= .3333333){
answer(weight*.1);
}
else if (age > .3333333 && age <= .583333){
answer(weight*.05);
}
else {
answer(weight*.04);
}
}

function foodOutput(age,weight){
if (age < 1) {
puppy(age,weight);
}
else {
adultDog(weight);
}
}
foodOutput(1,15);


/************************************************************** Task 4 **************************************************************/
Expand All @@ -59,6 +114,17 @@
// 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 result(final){
console.log("You",final);
}

function pcSays(RPS){
if (Math.random <= .33333){
console.log(result(final = RPS*2));
}
}

*/



Expand All @@ -67,13 +133,21 @@
//Metric Converter
//a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles



function kmTOmiles(kmNumber,miles){
return kmNumber*miles;
}
let noodle = kmTOmiles(32,.62137);
console.log(noodle);


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


function ftTOcm(ftNumber,centi){
return ftNumber/centi;
}
let smallRuler = ftTOcm(32,.032808);
console.log(smallRuler);



Expand All @@ -82,10 +156,47 @@
// 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 bottleDown(){

for (let i = 99; i--;);

var bottle = Math.round(Math.random());

if (bottle === 1){
console.log(bottle);
}
}
flip (98);
*/
function bottleToss(icase,jcase){


for (i = 99 ; i > 0 ; i--) {
j = i - 1;
if (i != 1) {
icase = "bottles";
} else {
icase = "bottle";
}
if (j != 1) {
jcase = "bottles";
} else {
jcase = "bottle";
}
console.log(icase,-1);
}
}
/* document.writeln(i + " " + icase + " of beer on the wall,");
document.writeln(i + " " + icase + " of beer,");
document.writeln("Take 1 down, pass it around,");
if (j != 0) {
document.writeln(j + " " + jcase + " of beer on the wall.");
} else {
document.writeln("No more bottles of beer on the wall!");
}
document.writeln()
}*/

/************************************************************** Task 7 **************************************************************/
//Grade Calculator
//write a javaScript program that takes a mark out of 100 and returns a corisponding letter grade
Expand All @@ -111,8 +222,3 @@
/************************************************************** Stretch **************************************************************/
//Take Rock, Paper, Sissors further
//update your rock papers sissors code below to take a prompt from a user using the window object