Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <head>
- <meta charset="UTF-8">
- <title>JavaScript challenge</title>
- <script>
- // HELLOCHILLE FUNCTION WONT BE CALLED ANYMORE WHEN COUNTER X BE MORE THAN 5
- var x = 0; // VARIABLE TO COUNT NUMBER OF TIMES HelloChile IS CALLED
- function HelloChile(msg) {
- alert(msg);
- }
- function CallHello() { // FUNCTION TO CALL HelloChile function
- x++; // INCREMENTING
- if (x < 5) {
- HelloChile("Hello Chile !");
- console.log("Hello chile");
- }
- else if (x == 5) { // IF BIGGER THAN 5 SO
- console.log("Hello chile last time");
- setTimeout(() => {
- HelloChile("Hello Chile for last time !");
- var newElementDOM = document.createElement("p");
- var textElement = document.createTextNode("Hello Chile cannot be called anymore.");
- newElementDOM.appendChild(textElement);
- document.body.appendChild(newElementDOM);
- }, 3000); // IF CALLED AFTER MULTIPLE TIMES SO IT WILL CALLED FOR LAST TIME AND AFTER 3 SECONDS
- }
- return false;
- }
- </script>
- </head>
- <body>
- <form>
- <button onclick="return CallHello();"> Call function </button>
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment