Advertisement
Fakher_AldeenOdeh

Lab 5 Assignment 2 (javascript)

Mar 11th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>by Fakher_Aldeen Odeh</title>
  5.     <script type="text/javascript">
  6.  
  7. window.onload = function(){
  8.  
  9.  
  10. document.getElementById('cli').onclick = function(){
  11.  
  12.  
  13. var random = Math.floor(Math.random()*(8-2)+2);
  14. var text1 = parseInt(document.getElementById('b').value);
  15.  
  16. var sum = 1;
  17.  
  18.         for(var i = 1;i<=random;i++){
  19.             sum*=text1;
  20.         }
  21.  
  22.  
  23. document.getElementById('res').innerHTML = "The result is : " + sum;
  24. document.getElementById('rand').innerHTML ="Generated random : " +  random;
  25.  
  26.  
  27.  
  28. }
  29.  
  30.  
  31.  
  32.  
  33. }
  34.  
  35.  
  36.  
  37.  
  38.     </script>
  39. </head>
  40. <body>
  41.  
  42.  
  43. Type a number : <input type="text" name="t" id="b" />
  44. <input type="button" name="b" id="cli" value="click"/><br>
  45.  
  46. <b id="res"></b>
  47. <b id="rand"></b>
  48.  
  49.  
  50.  
  51.  
  52. </body>
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement