Advertisement
Felanpro

Math functions

Jun 11th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4.  
  5. <head>
  6.  
  7. <head>
  8.  
  9.     <title>Training</title>
  10.  
  11. </head>
  12.  
  13. <body>
  14.  
  15. <button onclick="math1()">Generate</button>
  16. <p id="text1"></p>
  17.  
  18. <button onclick="math2()">Generate</button>
  19. <p id="text2"></p>
  20.  
  21. <button onclick="math3()">Generate</button>
  22. <p id="text3"></p>
  23.  
  24. <button onclick="math4()">Generate</button>
  25. <p id="text4"></p>
  26.  
  27. <button onclick="math5()">Generate</button>
  28. <p id="text5"></p>
  29.  
  30. <button onclick="math6()">Generate</button>
  31. <p id="text6"></p>
  32.  
  33. <script>
  34.    
  35.     //Math.random() //Returns number lower than 0.
  36.     function math1()
  37.     {
  38.         document.getElementById("text1").innerHTML = Math.random();
  39.     }
  40.    
  41.     //Math.min()
  42.     function math2()
  43.     {
  44.         document.getElementById("text2").innerHTML = Math.min(14, 27, 8, 34); //Return the lowest number.
  45.     }
  46.    
  47.     //Math.max()
  48.     function math3()
  49.     {
  50.         document.getElementById("text3").innerHTML = Math.max(14, 27, 8, 34); //Returns the biggest number.
  51.     }
  52.    
  53.     //Math.round()
  54.     function math4()
  55.     {
  56.         document.getElementById("text4").innerHTML = Math.round(4.4); //Returns the nearest number.
  57.     }
  58.    
  59.     //Math.ceil()
  60.     function math5()
  61.     {
  62.         document.getElementById("text5").innerHTML = Math.ceil(4.4); //Rounds a number up to the nearest integer.
  63.     }
  64.    
  65.     //Math.floor()
  66.     function math6()
  67.     {
  68.         document.getElementById("text6").innerHTML = Math.floor(4.4); //Rounds a number down to the nearest integer.
  69.     }
  70.    
  71.    
  72. </script>
  73.    
  74. </body>
  75.  
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement