Web Development Bootcamp by Angela Yu
: javascript practice
function isLeap(year) {
if (year%4===0 && year%100!==0 || year%400===0) {
return "Leap year.";
}
else {
return "Not leap year.";
}
for(var i=1; i<=100; i++) {
if (i%15===0) { // put fizzbuzz if first as it reads from the front
console.log("fizzbuzz");
}
else if (i%5===0) {
console.log("buzz");
}
else if (i%3===0) {
console.log("buzz");
}
else {
console.log(i);
}
}
Pick a random person
: using array and math.random
function whoPaying(names) {
var names=["A","B","C","D","E"];
var whatNames= Math.floor(Math.random()*names.length);
return (names[whatNames] +" is going to buy lunch today!");
}
whoPaying(names);
function beer() {
var number = 99;
while (number >= 0) {
var decrement = number--;
if (decrement > 1) {
console.log(decrement + " bottles of beer on the wall, " + decrement + " bottles of beer. Take one down and pass it around, " + (decrement - 1) + " bottles of beer on the wall.");
}
else if (decrement === 1) {
console.log(decrement + " bottle of beer on the wall, " + decrement + " bottle of beer. Take one down and pass it around, " + (decrement - 1) + " bottles of beer on the wall.");
}
else (decrement === 0) {
console.log("No a penny on me to buy more.");
}
}
}
beer();