Created
April 24, 2017 14:55
-
-
Save wismer/b8e9533c1dddc8eab4f1de83dcccd1ae to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=b8e9533c1dddc8eab4f1de83dcccd1ae
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> | |
<title>For Loop do now</title> | |
</head> | |
<body> | |
<button>click here</button> | |
</body> | |
</html> |
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
{"enabledLibraries":["jquery"]} |
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
//button click handler | |
// the slow way | |
var n = 0; | |
// I start out with a number that gets displayed in the HTML | |
$('body').append("<p>" + n + "</p>"); | |
// and everytime I do that, I increase "n" by 1 | |
n = n + 1; | |
$('body').append("<p>" + n + "</p>"); | |
// But this way | |
n = n + 1; | |
$('body').append("<p>" + n + "</p>"); | |
// is really, really repetitive and annoying | |
n = n + 1; | |
$('body').append("<p>" + n + "</p>"); | |
// but there is a faster way. | |
$("button").click(function(){ | |
//for loop declaration | |
for(var count = 0; count < 6; count = count + 1){ | |
//prints hello to the page body | |
$("body").append("<p>" + count + "</p>"); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment