Skip to content

Instantly share code, notes, and snippets.

@omas
Created July 5, 2014 08:02
Show Gist options
  • Select an option

  • Save omas/329086872f90406c3df2 to your computer and use it in GitHub Desktop.

Select an option

Save omas/329086872f90406c3df2 to your computer and use it in GitHub Desktop.
<!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