Created
May 29, 2017 13:35
-
-
Save seokju-na/51487b6982c10aaa9db33e5843aa18ff to your computer and use it in GitHub Desktop.
KWEB 4주차 과제 답안 예시
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
// 4주차 답안 예시 | |
var danCheck = /^[1-9]{1}$/; | |
/* | |
>>How to check the input<< | |
danCheck.test(input) | |
[input: number] | |
return: true (if input is a number between 1 and 9) | |
false (otherwise) | |
ex. | |
input |return | |
--------|-------- | |
1 |true | |
"1" |false | |
12 |flase | |
8 |true | |
"abc" |flase | |
*/ | |
function myFunc1() { | |
var num = document.getElementById('dan').value; | |
if (!danCheck.test(num)) { | |
return; | |
} | |
var str = ''; | |
for (var i = 1; i <= 9; i++) { | |
var result = num * i; | |
str += (num + ' X ' + i + ' = ' + result); | |
str += '\n'; | |
} | |
alert(str); | |
} | |
function myFunc2() { | |
var num = document.getElementById('dan').value; | |
if (!danCheck.test(num)) { | |
return; | |
} | |
var str = ''; | |
for (var i = 1; i <= 9; i++) { | |
var result = num * i; | |
str += (num + ' X ' + i + ' = ' + result); | |
str += '<br />'; | |
} | |
var timesTable = document.getElementById('timesTable'); | |
timesTable.innerHTML = str; | |
} | |
function clearTable() { | |
var timesTable = document.getElementById('timesTable'); | |
timesTable.innerHTML = 'Change here!!'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment