Created
July 5, 2014 08:02
-
-
Save omas/329086872f90406c3df2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <!-- | |
| 1. コマンドラインに「今日は何月何日でしょう?」のメッセージを表示する。 | |
| 2. それぞれ、「何月? ==> 」「何日? ==> 」を表示して入力を受け取る。 | |
| 3. 入力された月日が今日であれば「正解!!」、間違っていれば「間違っています」と表示する。 | |
| --> | |
| <script> | |
| (function(){ | |
| var input = {}; | |
| output("今日は何月何日でしょう?"); //condition 1 | |
| input.month = Number(prompt("何月? ==>")); //condition 2 | |
| input.date = Number(prompt("何日? ==>")); //condition 2 | |
| if (isToday(input)){ //condition 3 | |
| output("正解!!"); | |
| } else { | |
| output("間違っています"); | |
| } | |
| })(); | |
| function isToday(input){ | |
| var today = new Date(); | |
| var month = today.getMonth() + 1; | |
| var date = today.getDate(); | |
| return ((month == input.month) && (date == input.date)); | |
| } | |
| function output(text){ | |
| alert(text); | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment