var score = prompt("성적을 입력하세요.");
if (score >= 90) {
console.log("A");
} else if (score >= 80) {
console.log("B");
} else if (score >= 70) {
console.log("C");
} else {
console.log("D");
}
switch
break
var language = prompt("언어를 입력해주세요.");
switch(language) {
case "korean":
alert("안녕하세요.");
break;
case "english":
alert("Hello.");
break;
case "spanish":
alert("Hola.");
break;
default:
alert("지원하지 않는 언어입니다.");
break;
}
function operator(x, y, func) {
return func(x, y);
}
function add(a, b) { return a+b; }
function substract(a, b) { return a-b; }
console.log(operator(4, 2, add));
console.log(operator(4, 2, substract));
<script>
var element = document.getElementById("text");
setTimeout(function() {
element.innerText = '삭제됨';
}, 3000);
</script>
today 에 저장되어 있는 날짜의 요일을 나타내는 0에서 6 사이의 수를 반환. 0은 일요일
전자시계 만들기
<p id="text" class="content"></p>
<script>
var element = document.getElementById("text");
var tick = function() {
var now = new Date();
var time = now.getHours() + '시' +
now.getMinutes() + '분' +
now.getSeconds() + '초';
element.innerText = time;
};
setInterval(tick, 1000);
</script>