Created
October 30, 2013 22:37
-
-
Save chikoski/7241550 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<input type="text" id="input"> | |
<button id="btn">スタート</button> | |
<ul id="list"></ul> | |
</body> | |
</html> |
This file contains hidden or 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 list = document.getElementById("list"); | |
var btn = document.getElementById("btn"); | |
var input = document.getElementById("input"); | |
var generateProgression = function(n){ | |
var progression = []; | |
var i = 0; | |
while(i < n){ | |
progression[i] = (i + 1); | |
i = i + 1; | |
} | |
return progression; | |
}; | |
var listProgressionTo = function(n){ | |
var progression = generateProgression(n); | |
var i = 0; | |
while(i < progression.length){ | |
list.innerHTML += "<li>" + progression[i] + "</li>"; | |
i = i + 1; | |
} | |
}; | |
btn.onclick = function(){ | |
var n = Number(input.value); | |
if(isNaN(n) || n < 0){ | |
n = 0; | |
} | |
listProgressionTo(n); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment