Created
September 22, 2018 18:06
-
-
Save ZASMan/cf992aa41ad6d1b0825f08dbc0ebbaf0 to your computer and use it in GitHub Desktop.
code_for_marcos
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
document.addEventListener("DOMContentLoaded", function(event) { | |
// ID's should be unique | |
// Button to click and execute prompt | |
var my_button = document.getElementById("my_button_id"); | |
// Try adding another element by ID. Such as a div to append the names to | |
// For example: | |
// var my_div = document.getElementById("my_div"); | |
// This is attaching a click event function with the function | |
// buttonAlert to the myButton ID | |
myButton.addEventListener("click", buttonAlert); | |
// You want to use named functions whenever possible | |
// to make your code more reusable | |
function buttonAlert() { | |
var name = prompt('What is your name?'); | |
alert('Hello ' + name + ', nice to meet you!'); | |
// Once you make the div | |
// my_div.innerHTML += name; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment