#TIL (April 26th, 열두번째 이야기)

Jung Hyun Kim·2020년 4월 26일
0

Web Development Bootcamp by Angela Yu

: javascript practice

1. Leap Year Challenge

  • How to check whether a given year is a leap year

    : A year is a leap year if it is evenly divisible by 4;
    : except if that year is also evenly divisible by 100;
    : unless that year is also evenly divisible by 400.

leapyear test

function isLeap(year) {
    
if (year%4===0 && year%100!==0 || year%400===0) {
    return "Leap year.";
} 

else {
    return "Not leap year.";
}

2. FizzBuzz Game( 3,6,9게임과 비슷)

  • Create an array with FizzBuzz Game
    : Any number divisible by three is replaced by the word fizz
    : Any number divisible by five by the word buzz
    : Numbers divisible by 15 become fizzbuzz
     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);
     }
       
     }

3. Who is buying lunch (이름 랜덤 뽑기)

  • 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);
    

4. 99 bottles challenge

  • Creating repeated lyrics
    : using while to complete
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();

5. Fibionachi challenge

profile
코린이 프론트엔드 개발자💻💛🤙🏼

0개의 댓글