Created
March 13, 2018 03:54
-
-
Save kaoru-fukusato/9162a525c46c173e25b452e6fac2f0e2 to your computer and use it in GitHub Desktop.
コピペで学べるプログラミング基本2-1
This file contains 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
<script type="text/javascript"><!-- | |
function myCheck(){ | |
myCnt = 0; // チェックした数 | |
for ( i=0; i<document.myForm.length-1; i++ ){ // チェックボックスの数分ループ | |
if ( document.myForm.elements[i].checked == true ){ // チェックはオンか? | |
myCnt++; // チェック数 加算 | |
} | |
} | |
if ( myCnt == 0 ) myMess = "正常"; // チェックは 無し(ゼロ) | |
else if ( myCnt <= 2 ) myMess = "ちょヤバ"; // チェックは 1以上2以下 | |
else if ( myCnt <= 4 ) myMess = "危険気味"; // チェックは 3以上4以下 | |
else myMess = "完璧に危険"; // チェックは 全部(5) | |
myComment = "危険度チェック 診断結果¥n¥nあなたは、" + myMess + "です!"; | |
alert ( myComment ); | |
} | |
// --></script> | |
<form name="myForm"> | |
<input type="checkbox">たばこは1日20本以上吸う<br> | |
<input type="checkbox">お酒を飲むと性格が変わる<br> | |
<input type="checkbox">車を運転すると性格が変わる<br> | |
<input type="checkbox">刃物を手にすると心がなごむ<br> | |
<input type="checkbox">ピストルを所持している<br> | |
<input type="button" onclick="myCheck()" value="診断"><br> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment