Advertisement
Guest User

Untitled

a guest
Jan 21st, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. # JAVASCRIPT
  2. ---
  3.  
  4. ## elm is one of the more popular functional languages
  5.  
  6. ### Three technologies add up to make a web page
  7.  
  8. * HTML (content
  9. * CSS (presentation)
  10. * JAVASCRIPT (behaviors)
  11.  
  12. #### Web Application Flow
  13. <<<IMAGE>>>
  14.  
  15. #### A Simple Demo
  16.  
  17. * HTML
  18. ```HTML
  19. <!DOCTYPE html>
  20. <html>
  21. <head>
  22. <meta charset="utf-8">
  23. <title></title>
  24. <script src="demo.js">
  25. </script>
  26. <script src="name.js">
  27. </script>
  28. </head>
  29. <body>
  30. <h1>Output</h1>
  31. <div id="output">
  32. </div>
  33. <div id ="name">
  34.  
  35. </div>
  36.  
  37. </body>
  38. </html>
  39. ```
  40. * Javascript
  41. ```Javascript
  42. \\demo.js
  43. document.addEventListener("DOMContentLoaded", function(event){
  44. var outputDiv = document.getElementById('output');
  45. var now = new Date();
  46. outputDiv.innerHTML = "Hello World! <br/>";
  47. outputDiv.innerHTML += "<p>"+ now + "</p>";
  48. }
  49. )
  50. \\name.js
  51. document.addEventListener("DOMContentLoaded", function(event) {
  52. var nameDiv = document.getElementById('name');
  53. nameDiv.innerHTML="Mallinath";
  54. })
  55.  
  56. ```
  57.  
  58. ### Developer Console
  59.  
  60. * In javascript, numbers are always floats
  61. * Equal statements have two forms (== and ====)
  62. * Strings coercion when combining with numbers will have a precedence on the left operator
  63. <<<IMAGE Strings>>>
  64. * Strings are immutable
  65. <<<IMAGE String Methods and Parsing>>>
  66.  
  67. ### Variables in Javascript
  68. <<<IMAGE variablesJS>>>
  69. * null and undefined NOT the same!
  70. <<<IMAGE ex_names_js>>>
  71.  
  72. ### COMMENTS
  73. * // -> this is a single line comment
  74. * /* */ -> this is a multi line comment
  75.  
  76. ### I/O in Javascript
  77.  
  78. * console.log("Hello");
  79. <<<IMAGE console_in_js>>>
  80.  
  81. ### Built-ins
  82.  
  83. * alert - to display a message
  84. * confirm - before proceeding, receive confirmation
  85. * prompt - to ask a question
  86.  
  87. <<<IMAGE - Builtins>>>
  88.  
  89. ### Booleans
  90. * true
  91. * false
  92. * > < == !=
  93. <<<IMAGE True of False exercise 1 & 2>>
  94. ```Javascript
  95. document.addEventListener("DOMContentLoaded", function(event){
  96. var outputDiv = document.getElementById('output');
  97. var now = new Date();
  98. var a = 3;
  99. var b = 4;
  100. var result = 3*4;
  101. var nameUser = prompt("What the hell is your name?");
  102. var safePass = confirm("Welcome to super-safe! Are you sure you want to enter?")
  103. if(safePass){
  104. if (nameUser.length > 12){
  105. alert("Too Long!")
  106. }
  107. else if(nameUser.length < 8) {
  108. alert("Too Short");
  109. }
  110. else {
  111. alert("Just Right");
  112. }
  113. }
  114. else {
  115. alert("Ok Thanks bye");
  116. }
  117.  
  118. outputDiv.innerHTML = "Hello " + nameUser + " In case you forgot,%i" + "X" + "%i is %s <br/>", a, b, result;
  119. alert("The current date and time is " + now);
  120. outputDiv.innerHTML += "<p>"+ now + "</p>";
  121. })
  122.  
  123. ```
  124. ### LOOPS IN JAVASCRIPT
  125.  
  126. #### WHILE LOOP
  127. <<<IMAGE while_diff_flavors.png>>>
  128.  
  129. ```Javascript
  130. //Print Even Numbers
  131. var i = 0;
  132. while (i<=100){
  133. console.log(i+=2);
  134. }
  135. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement