[JavaScript] Prompt, Alert, Confirm


const name = prompt("Put your name");


prompt can put default 

const name = prompt("Put your Date of Birth", "12/25/2002");



alert("welcome, " + name );


confirm(Are you an adult?)   ------- True or False




Let's say Eng: 90, Math: 60 
4530

However, we got odd number. because prompt input the value as "string" so the numbers we put was recognized as "string".   





Boolean

Number(null) // 0

Number(undefined) // Nan


Number(0) // False

Number("0") // True


Number("") // False

Number(" ") // True 



const num 2**3;

console.log(num);    // 8






                                                       True


===   :  asking the type as well 



                                                          False


If Statement

   const age = 10;

if(age > 19){
  console.log("Welcome");
} else if (age === 19) {
  console.log("You're 19 !")
} else {
  console.log("sorry")
}




|| (OR)
&& (and)
! (Not)


const name = "Mike";
const age = 30;

if(name === "Tom" || age > 19){
    console.log("pass");
} else {
    console.log("Turn back");
}


const age = prompt("Your age?")
const isAge = age > 19;

if(!isAge){
    console.log("Sorry");
} else {
  console.log("Welcome");
}



const gender = "F";
const name = "John";
const age = 22;

if(gender === "M" && (name === "Mike" || age === 19)){
    console.log("Go ahead");
};




Popular posts from this blog

[Python] Dictionary

[Visual Design 2/3]

[JavaScript] For loop , Function