<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<input id='times' type='text' maxlength="4" />
<input type='button' value='時間判斷'
onclick='CheckTime()'/>
<p></p>
<a id='timeresult'></a>
<p></p>
<input id='numbers' type='text' />
<input type='button' value='數字判斷'
onclick='CheckNum()'/>
<p></p>
<a id='result'></a>
</body>
</html>
function CheckTime() {
var times = document.getElementById('times');
var hour = times.value.substring(0, 2);
var timeresult = document.getElementById('timeresult');
if (hour > 12) {
timeresult.innerText = '輸入的時間為下午。';
}
else {
timeresult.innerText = '輸入的時間為上午。';
}
}
function CheckNum() {
var numbers = document.getElementById('numbers');
var result = document.getElementById('result');
var x = numbers.value.split('');
var even = 0, odd = 0;
var num0 = 0, num1 = 0, num2 = 0, num3 = 0, num4 = 0,
num5 = 0, num6 = 0, num7 = 0, num8 = 0, num9 = 0;
for (var i = 0; i < x.length; i++) {
if (x[i] % 2 == 0) {
even++;
}
else {
odd++;
}
switch (x[i]) {
case "0":
num0++;
break;
case "1":
num1++;
break;
case "2":
num2++;
break;
case "3":
num3++;
break;
case "4":
num4++;
break;
case "5":
num5++;
break;
case "6":
num6++;
break;
case "7":
num7++;
break;
case "8":
num8++;
break;
case "9":
num9++;
break;
default:
}
}
result.innerText ='\n輸入的數字串為 ' + numbers.value + ' \n偶數:' + even + ' \n奇數:' + odd;
result.innerText += '\n'
+ '0:' + num0 + '個\n'
+ '1:' + num1 + '個\n'
+ '2:' + num2 + '個\n'
+ '3:' + num3 + '個\n'
+ '4:' + num4 + '個\n'
+ '5:' + num5 + '個\n'
+ '6:' + num6 + '個\n'
+ '7:' + num7 + '個\n'
+ '8:' + num8 + '個\n'
+ '9:' + num9 + '個\n';
}
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |