Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <meta charset="UTF-8">
  6. <meta name="description" content="Lab test 2 for COMP1231">
  7. <meta name="keywords" content="Lab test 2, COMP1231, Loops">
  8. <meta name="author" content="Brendan Bernas brendan.bernas@georgebrown.ca">
  9. <title>Lab Test 2</title>
  10. </head>
  11. <body>
  12. <h1>Lab Test 2</h1>
  13. <div id="divWrite"></div>
  14. <script>
  15. var userMin = prompt("Please enter the first number");
  16. var userMax = prompt("Please enter the second number");
  17. var outputString = ""
  18.  
  19. if (isNaN(userMin) || isNaN(userMax)) //checks if either input is not a number
  20. {
  21. outputString = "Please enter two numbers";
  22. }
  23. else if (userMin >= userMax)
  24. {
  25. outputString = "Please make sure the second number is greater than the first number";
  26. }
  27. else
  28. {
  29. var i = 1; //reset counter
  30. var count = userMin;
  31. while (count < userMax) //repeats block until it reaches the max number
  32. {
  33. i = 1;
  34. while (i <= count)
  35. {
  36. outputString += "*";
  37. i++;
  38. }
  39. outputString += "<br>";
  40. count++;
  41. }
  42. while (count >= userMin) //repeats block from max number to min number
  43. {
  44. i = 1;
  45. while (i <= count)
  46. {
  47. outputString += "*";
  48. i++;
  49. }
  50. outputString += "<br>";
  51. count--;
  52. }
  53.  
  54.  
  55. }
  56. document.getElementById("divWrite").innerHTML = outputString;
  57. </script>
  58. <hr>
  59. <script src=http://my.gblearn.com/js/loadscript.js></script>
  60.  
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement