Advertisement
Guest User

function demo in JS

a guest
Apr 26th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.85 KB | None | 0 0
  1. <html>
  2.     <head>
  3.     </head>
  4.     <body>
  5.         <center>
  6.             <h1>
  7.                 My first calculator<br/>
  8.             </h1>
  9.             <h2>
  10.                 <p id="myAns"></p>
  11.             </h2>
  12.         </center>  
  13.         <script>
  14.             // setting empty string
  15.             var myAnswer="";
  16.             myData();
  17.            
  18.             function myData()
  19.             {
  20.                 myAnswer+=calc(2,3);
  21.                 //2,3          
  22.                 //5,8
  23.                 myAnswer+=calc(5,8);
  24.                 //9,2
  25.                 myAnswer+=calc(9,2);
  26.                 //5,25
  27.                 myAnswer+=calc(5,25);
  28.                 //7,7
  29.                 myAnswer+=calc(7,7);
  30.                 //10,8
  31.                 myAnswer+=calc(10,8);
  32.                 //display the answer to the html
  33.                 myAns.innerHTML=myAnswer;
  34.                 writeConsoleFinish();
  35.             }
  36.            
  37.             function calc(num1,num2)
  38.             {
  39.                 var returnString="<i>"+num1+" + "+num2+" = "+(num1+num2)+"</i><br/>";
  40.                 return returnString;
  41.             }
  42.            
  43.             function writeConsoleFinish()
  44.             {
  45.                 console.log("finished");
  46.             }
  47.         </script>      
  48.     </body>
  49. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement