Created
August 16, 2017 18:29
-
-
Save mxdi9i7/20b65c6b7aa4751088110fbab05e8e4c to your computer and use it in GitHub Desktop.
JS practice
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
<!Doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
<input type="number" id="input1"> | |
<button id="btn">Calculate</button> | |
<h1 id="demo"></h1> | |
</body> | |
<script src="index.js"></script> | |
</html> |
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
var input1 = document.getElementById('input1') | |
var btn = document.getElementById('btn') | |
var demo = document.getElementById('demo'); | |
function evenOrOdd(x) { | |
if (x == 0) { | |
demo.innerHTML = "0 既不是奇数也不是偶数" | |
} else if (x % 2 == 0) { | |
demo.innerHTML = x + " 是偶数" | |
} else { | |
demo.innerHTML = x + ' is Odd' | |
} | |
} | |
for(var i = 0; i < 5; i++) { | |
console.log('这次循环, i 是 ' + i) | |
} | |
btn.addEventListener('click', function() { | |
evenOrOdd(input1.value) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment