Drink Conditionals
if (old <= 13) {
return 'drink toddy';
} else if (old > 13 && old <18) {
return 'drink coke';
} else if (old > 17 && old <21) {
return 'drink beer';
} else {
return 'drink whisky';
}
};
//receives age as old parameter
//0-13 drink toddy
//14-17 drink coke
//18-20 drink beer
//21+ drink whiskey
//returns what they drink
Array Plus Array
var addElements = 0
for (var i = 0; i < arr1.length; i++) {
addElements += arr1[i]
}
for (var j = 0; j < arr2.length; j++) {
addElements += arr2[j]
}
return addElements
};
//sum up each element inside of array1 using a for loop
//sum up each element inside of array2 using anot
//add array1 to array2
//return total
Find the Smallest Integer in an Array
findSmallestInt(args) {
var smallestNumber = args[0];
for ( var i = 0; i < args.length; i++) {
if (smallestNumber > args[i]) {
var smallestNumber = args[i]
console.log(smallestNumber)
}
}
return smallestNumber
}
}
//search for the smallest number in the args array
//working with numbers in an array
//use a for loop to search the values inside of the array
//create a variable outside of loop that is set to zero
//run the loop and use the variable set to zero to access the smallest integer in the array
//return the smallest integer