Java Script/JS basic

JS] Arrays / 명단에 이름확인 퀴즈

CodeMia 2021. 8. 14. 15:59

 

 

사용자에게 이름 물어보고

guestList에 이름 있는지 확인후 

이름 있으면 "welcome, name"

이름 없으면 "Sorry, you're not on the list."

내용 띄우기 

 

 

var guestList = ["Jane", "Adam", "John", "Jack", "Jean"];
var guestName = prompt("what's your name?");

if (guestList.includes(guestName)) {
    alert("welcome "+ guestName);
} else {
    alert("Sorry "+ guestName +", You're not on the list.");
}