Created
November 5, 2015 04:52
-
-
Save kidmillions/176aaaf1888ce93af187 to your computer and use it in GitHub Desktop.
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"> | |
<title></title> | |
</head> | |
<body> | |
<div id="target"> | |
</div> | |
<script> | |
//Create a variable n and assign it an integer. | |
var n = 10; | |
// Code a while loop that builds as a single string, the numbers 1 through n, separated by commas | |
var number = 1; | |
var result = ""; | |
while(number <= n) { | |
result += number; | |
if (number < n) { | |
result += ", " | |
} | |
number++; | |
} | |
document.getElementById('target').textContent = result; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment