IT Study/Web
[JavaScript] 응용 예제 - string
도뿌리
2018. 8. 6. 14:43
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <h3>(문제)</h3> 영어 속담으로"1일 1개씩 먹으면 의사 필요없다"라고 하는 과일은 무엇일까요? <br><br> □영어(소문자)로 답한다 <br><br> 답: <input type="text" id="value" size="10"> <button type="button" onclick="check()">답을 체크</button> <script type="text/javascript"> function check() { var value = document.getElementById("value").value; //자바 스크립트에선 equals 사용 ㄴㄴ if(value == "apple") alert("정답입니다."); else alert("틀렸습니다."); } </script> </body> </html> | cs |
문자열 비교 시 equals를 안쓰고 등호기호( == ) 로 비교