Skip to content

Instantly share code, notes, and snippets.

@kidmillions
Created November 5, 2015 04:52
Show Gist options
  • Save kidmillions/176aaaf1888ce93af187 to your computer and use it in GitHub Desktop.
Save kidmillions/176aaaf1888ce93af187 to your computer and use it in GitHub Desktop.
<!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