Javascript First Lesson

Functions

function lifeIn(age) {
    var day=(90-age)*365;
    var week=(90-age)*52;
    var month=(90-age)*12;
    console.log("You have "+day+" days,"+week+" weeks,"+month+" months left.");
}

lifeIn(56);

Arrays

var guestName=prompt("what's your name?");

var guestList=["Angela","Jack","Sam","Andrea","Messi","Erdi"];

if(guestList.includes(guestName)){
    console.log("Welcome!");
}
else{
    console.log("Sorry, maybe next time.");
}

includes is true or false return value.

3 fizz 5 buzz 3 and 5 fizzbuzz write code:

var output=[];
var count=1;

function fizzBuzz() {
if(count%3===0 && count%5===0)
{
    output.push("FizzBuzz");
}
    else if(count%3===0){
        output.push("fizz");
    }
        else if(count%5===0){
           output.push("buzz"); 
        }
    else{
        output.push(count);
    }

    count++;
    

    console.log(output);
}

Print:

functions, arrays and math library(floor – random):

var names=["angela","ben","Jenny","Micheal","Chloe"];

function whosPaying(names) {

    var numberOfPeople=names.length;
    var rnd=Math.floor(Math.random()*numberOfPeople);
    var randomPerson=names[rnd];

    return randomPerson+" is going to buy lunch today.";
    
}

whosPaying(names);

Print: