Guest User

Untitled

a guest
Jan 20th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <head>
  3. <meta charset="UTF-8">
  4. <title>JavaScript challenge</title>
  5. <script>
  6. // HELLOCHILLE FUNCTION WONT BE CALLED ANYMORE WHEN COUNTER X BE MORE THAN 5
  7. var x = 0; // VARIABLE TO COUNT NUMBER OF TIMES HelloChile IS CALLED
  8.  
  9. function HelloChile(msg) {
  10. alert(msg);
  11. }
  12.  
  13. function CallHello() { // FUNCTION TO CALL HelloChile function
  14. x++; // INCREMENTING
  15. if (x < 5) {
  16. HelloChile("Hello Chile !");
  17. console.log("Hello chile");
  18. }
  19. else if (x == 5) { // IF BIGGER THAN 5 SO
  20. console.log("Hello chile last time");
  21. setTimeout(() => {
  22. HelloChile("Hello Chile for last time !");
  23. var newElementDOM = document.createElement("p");
  24. var textElement = document.createTextNode("Hello Chile cannot be called anymore.");
  25. newElementDOM.appendChild(textElement);
  26. document.body.appendChild(newElementDOM);
  27. }, 3000); // IF CALLED AFTER MULTIPLE TIMES SO IT WILL CALLED FOR LAST TIME AND AFTER 3 SECONDS
  28. }
  29.  
  30. return false;
  31. }
  32.  
  33. </script>
  34.  
  35. </head>
  36.  
  37. <body>
  38.  
  39. <form>
  40.  
  41. <button onclick="return CallHello();"> Call function </button>
  42.  
  43. </form>
  44.  
  45. </body>
  46.  
  47. </html>
Add Comment
Please, Sign In to add comment