Advertisement
Patrikrizek

lesson-7-index

Mar 24th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.99 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>JS examples</title>
  8.  
  9. </head>
  10. <body>
  11.  
  12.     <h1>JavaScript</h1>
  13.  
  14.     <!-- Two Examples of JavaScript funcions (sum of digits and combinig Strings) -->
  15.     <script>
  16.  
  17.         function myFunction(x,y) {
  18.             let sum = 0;    // sum is undefind
  19.             sum = x + y;    // sum has values (total) of x + y
  20.             return sum;     // retrn the value of the sum
  21.         }
  22.  
  23.         console.log(myFunction(4,5));
  24.  
  25.         function myText(a, b, c) {
  26.             let myText = "";
  27.             myText = a + " " + b + " " + c;
  28.             return myText;
  29.         }
  30.  
  31.         console.log(myText("Joe", "Doe", "Second"));
  32.  
  33.         // display message in console
  34.         console.log(7+8);
  35.  
  36.     </script>
  37.  
  38.     <!-- Alert JavaScript -->
  39.     <script>
  40.  
  41.         // display this message in the allert pop up box.
  42.         window.alert("This is my text!");
  43.  
  44.     </script>
  45.  
  46.     <p id="demo">    </p>
  47.     <p id="example">   </p>
  48.  
  49.     <!-- inherHTML JavaScript -->
  50.     <script>
  51.  
  52.         // insert value in the tag with specific ID
  53.         document.getElementById("demo").innerHTML = "Hello World!";
  54.         document.getElementById("example").innerHTML = 5 + 7;
  55.     </script>
  56.  
  57.  
  58. <br>
  59. <br>
  60. <br>
  61. <br>
  62.  
  63. <!-- Basic JavaScript onclick method -->
  64. <h1>Display my name below</h1>
  65.  
  66. <form>
  67.     <label for="fName">Name</label><br>
  68.     <input type="text" name="fName" id="firstName" placeholder="John">
  69.     <br>
  70.     <input type="button" value="Display my Name" onclick="replaceText()">
  71. </form>
  72.  
  73. <p id="output">Your Name will be displayed here.</p>
  74.  
  75. <script>
  76.  
  77.     function replaceText() {
  78.  
  79.         var myName = document.getElementById("firstName").value;
  80.         document.getElementById("output").innerHTML = "Your input Name is: " + myName;
  81.  
  82.     }
  83.  
  84. </script>
  85.    
  86. </body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement