Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>JavaScript in 12 Minuets</title>
  5. </head>
  6. <body>
  7.  
  8. <h3>document.write</h3>
  9. <script>
  10.  
  11. document.write("Hello, World!");
  12.  
  13. </script>
  14.  
  15. <br>
  16.  
  17. <h3>variables</h3>
  18. <script>
  19.  
  20. var myvariable = 5; // this can be a number, a string or bolean
  21.  
  22. </script>
  23.  
  24. <br>
  25.  
  26. <h2>variables with operators </h2>
  27.  
  28. <h3>concontinate = to add them together</h3>
  29. <script>
  30.  
  31. var words = "This is";
  32. var moreWords = " a sentence";
  33. var sentence = words + moreWords;
  34. document.write(sentence);
  35.  
  36. </script>
  37.  
  38. <br>
  39. <br>
  40.  
  41. <h3>totaling by adding, subtraction, multiplying and division</h3>
  42. <script>
  43.  
  44. var num1 = 5;
  45. var num2 = 3;
  46. var total = num1 + num2; // subtract -, add +, divied /, multiply *, find the remainder after with %, if you use ++ will add 1, -- will subtract 1
  47. document.write(total);
  48.  
  49. </script>
  50.  
  51. <br>
  52. <br>
  53.  
  54. <h3>Strings are stored as objects</h3>
  55.  
  56. <script>
  57. // This is an objet - just information
  58. var alpha = "ABCDEFG"; // string
  59.  
  60. var length = alpha.length;
  61. document.write(length);
  62. document.write("<br>"); // adds a break between the html lines
  63.  
  64. // This is a methode, it can take input, do computation, and then output the answer, substring will take a portion of the string,
  65. var result = alpha.substring(0, 5);
  66. document.write(result);
  67.  
  68. </script>
  69.  
  70. <br>
  71. <br>
  72.  
  73. <h3>Arrays</h3>
  74. <!-- Arrays hold many values in a single variable -->
  75. <script>
  76.  
  77. var a = new Array(7);
  78. a[0] = "cat";
  79. a[1] = "dog";
  80. a[2] = 95;
  81. a[3] = "something else";
  82. a[6] = true;
  83.  
  84. document.write(a[1]);
  85.  
  86. </script>
  87.  
  88. <br>
  89. <br>
  90.  
  91. <!-- the same array but written shorter -->
  92. <script>
  93.  
  94. var a = new Array("cat","dog", 95, "something else", true);
  95.  
  96. document.write(a[1]);
  97.  
  98. </script>
  99.  
  100. <br>
  101. <br>
  102.  
  103. <!-- and another shorter way with the same array -->
  104. <script>
  105.  
  106. var a = ["cat","dog", 95, "something else", true];
  107.  
  108. document.write(a[3]);
  109.  
  110. </script>
  111.  
  112. <br>
  113. <br>
  114.  
  115. <h2>defining functions</h2>
  116.  
  117. <!-- functions can be called to be reused, good habit to be able to reuse functions -->
  118. <script>
  119.  
  120. function sayHello(who) {
  121. document.write("Hello");
  122. }
  123.  
  124. </script>
  125.  
  126. <!-- you call the function like this below someplace within the body -->
  127. <script>
  128.  
  129. sayHello();
  130.  
  131. </script>
  132.  
  133. <br>
  134. <br>
  135.  
  136. <h2>defining functions with more than one variable</h2>
  137.  
  138. <!-- functions can be called to be reused, good habit to be able to reuse functions, they can also be used like below with multiple variables -->
  139. <script>
  140.  
  141. function sayHello(who) {
  142. document.write("Hello, " + who);
  143. }
  144.  
  145. </script>
  146.  
  147. <!-- you call the function like this below simeplace within the body -->
  148. <script>
  149.  
  150. sayHello("Bob");
  151. document.write("<br>");
  152. sayHello("Mary");
  153.  
  154. </script>
  155.  
  156. <br>
  157. <br>
  158.  
  159. <h2>flow control statements - if statements object-numeric</h2>
  160. <script>
  161.  
  162. var a = 12;
  163. if (a > 10) { // < less than, > greater than, >= greater than or equal to, <= less than or equal to, != not equal to, == equals (last two for strings)
  164. alert(a);
  165. }
  166.  
  167. </script>
  168.  
  169. <br>
  170. <br>
  171.  
  172. <h2>flow control statements - if statements as a string</h2>
  173. <script>
  174.  
  175. var a = "jake";
  176. if (a == "Jake") { // < less than, > greater than, >= greater than or equal to, <= less than or equal to, != not equal to, == equals (last two for strings)
  177. alert(a);
  178. } else {
  179. alert("The condition was false");
  180. }
  181.  
  182. </script>
  183.  
  184. <br>
  185. <br>
  186.  
  187. <h2>flow control statements - for loop </h2>
  188.  
  189. <script>
  190.  
  191. for (i=0;i<5;i++) { // counter variable, condition (< than 5), increment i or the counter variable) it will produce results going from 0 thru 4
  192. document.write("This is iteration " + i + "<br>"); // this concantinates the string with the current value of i and then concantinate the html line break <br> to make the output neater and more readable
  193. }
  194.  
  195. </script>
  196.  
  197. <br>
  198. <br>
  199.  
  200. <h2>flow control statements - for loop, same as above but with change in counter </h2>
  201.  
  202. <script>
  203.  
  204. for (i=1;i<6;i++) { // counter variable, condition (< than 5), increment i or the counter variable) by changing the counter variable from 0 to 1 and the condition from 5 to 6 it will produce results going from 1 thru 5
  205. document.write("This is iteration " + i + "<br>"); // this concantinates the string with the current value of i and then concantinate the html line break <br> to make the output neater and more readable
  206. }
  207.  
  208. </script>
  209.  
  210. <br>
  211. <br>
  212.  
  213. <script>
  214.  
  215. </script>
  216.  
  217. </body>
  218. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement