Advertisement
Patrikrizek

lesson-7-example

Jun 20th, 2022
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.38 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.     <!-- This is the example of internal JS -->
  10.     <script>
  11.         //code here
  12.     </script>
  13.  
  14.     <!-- This is an external JS file. -->
  15.     <script src="jsExternal.js"></script>
  16.    
  17. </head>
  18. <body>
  19.    
  20.     <h1>JavaScript</h1>
  21.    
  22.     <!-- This is the example of internal JS -->
  23.     <script>
  24.         //code here
  25.     </script>
  26.  
  27.     <!-- This is an external JS file. -->
  28.     <script src="jsExternal.js"></script>
  29.  
  30.     <!-- Two Examples of JavaScript functions (sum of digits and combining Strings) -->
  31.     <script>
  32.  
  33.         function myFunction(x,y) {
  34.             var sum = 0;    // sum is undefined
  35.             sum = x + y;    // sum has values (total) of x + y
  36.             return sum;     // return the value of the sum
  37.         }
  38.  
  39.         console.log(myFunction(4,5));
  40.  
  41.         function myText(a, b, c) {
  42.             var myText = "";
  43.             myText = a + " " + b + " " + c;
  44.             return myText;
  45.         }
  46.  
  47.         console.log(myText("Joe", "Doe", "Second"));
  48.  
  49.         // display message in console
  50.         console.log(7+8);
  51.  
  52.     </script>
  53.  
  54.     <!-- Alert JavaScript -->
  55.     <script>
  56.  
  57.         // display this message in the alert pop up box.
  58.         window.alert("This is my text!");
  59.  
  60.     </script>
  61.  
  62.     <p id="demo">    </p>
  63.     <p id="example">   </p>
  64.  
  65.     <!-- inherHTML JavaScript -->
  66.     <script>
  67.  
  68.         // insert value in the tag with specific ID
  69.         document.getElementById("demo").innerHTML = "Hello World!";
  70.         document.getElementById("example").innerHTML = 5 + 7;
  71.     </script>
  72.  
  73.  
  74. <br>
  75. <br>
  76. <br>
  77. <br>
  78.  
  79. <!-- Basic JavaScript onclick method -->
  80. <h1>Display my name below</h1>
  81.  
  82. <form>
  83.     <label for="fName">Name</label><br>
  84.     <input type="text" name="fName" id="firstName" placeholder="John">
  85.     <br>
  86.     <input type="button" value="Display my Name" onclick="replaceText()">
  87. </form>
  88.  
  89. <p id="output">Your Name will be displayed here.</p>
  90.  
  91. <script>
  92.  
  93.     function replaceText() {
  94.  
  95.         var myName = document.getElementById("firstName").value;
  96.         document.getElementById("output").innerHTML = "Your input Name is: " + myName;
  97.  
  98.     }
  99.  
  100. </script>
  101.    
  102. </body>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement