Crenox

Javascript Tutorial For Beginners LearnCode.academy #4

Jul 6th, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html class="no-js">
  3. <html>
  4. <head>
  5. <meta charset="utf-8">
  6. <title>Javascript</title>
  7. <meta name="description" content="">
  8. <meta name="viewport" content="width=device-width">
  9. <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css"/>
  10. <link rel="stylesheet" href="styles/main.css">
  11. </head>
  12.  
  13. <body>
  14. <div class="container">
  15. <div class="jumbotron">
  16. <h1>Let's Learn Javascript!</h1>
  17. <p class="lead">...cause Javascript ROCKS.</p>
  18. </div>
  19.  
  20. </div>
  21. <script src="scripts/main.js"></script>
  22. </body>
  23. </html>
  24. <!-- It's always good to put the script before the body so that it creates a much faster feeling webpage. -->
  25. -----------------------------------------------------------------------------------------------------------------------------
  26. /*
  27. // array of food
  28. var myList = ['apples', 'oranges', 'bananas'];
  29.  
  30. // calling the first item from myList, it's at the 0 index
  31. alert(myList[0]);
  32.  
  33. // defining the 3rd index (4th item) of myList
  34. myList[3] = 'pineapples';
  35. alert(myList[3]);
  36.  
  37. // changing the first item
  38. myList[0] = 'watermelon';
  39. alert(myList[0]);
  40. */
  41.  
  42. /*
  43. function go()
  44. {
  45. alert('hi');
  46. }
  47.  
  48. // we have a string, number, function, then an array of names within myList
  49. var myList = ['apples', 12, go, ['Will', 'Laura']];
  50.  
  51. alert(myList);
  52.  
  53. // calling the function go() from myList
  54. alert(myList[2]);
  55. */
  56.  
  57. /*
  58. var myList = ['apples', 'oranges', 'bananas'];
  59.  
  60. // shifts all of the fruit over thus removing the first index
  61. myList.shift();
  62.  
  63. // apples will not appear since it got shifted
  64. alert(myList);
  65. */
  66.  
  67. /*
  68. var myList = ['apples', 'oranges', 'bananas'];
  69.  
  70. // removes the last index of your array
  71. myList.pop();
  72.  
  73. // bananas will be gone when alerted
  74. alert(myList);
  75. */
  76.  
  77. /*
  78. var myList = ['apples', 'oranges', 'bananas'];
  79.  
  80. so what this does is it's going to automatically give you a value and index for each item inside of your list
  81. and then whatever you do in the function for the value and index it'll effect each and every item
  82. in it
  83. myList.forEach(function(value, index)
  84. {
  85. console.log(value, index);
  86. alert('I have ' + value + ' in my shopping bag which is located at index ' + index + ".");
  87. });
  88. */
  89.  
  90. /*
  91. WHILE LOOP
  92. var times = 0;
  93.  
  94. while(times < 10)
  95. {
  96. console.log("Number: ", times);
  97. times++;
  98. }
  99. */
  100.  
  101. /*
  102. DO WHILE LOOP
  103. var times = 0;
  104.  
  105. do
  106. {
  107. console.log("Number: ", times);
  108. times++;
  109. } while(times < 10)
  110. */
  111.  
  112. /*
  113. FOR LOOP
  114. Basic setup of a for loop
  115. for (setup, comparison, change)
  116. {
  117.  
  118. }
  119.  
  120. for (var i = 0; i < 10; i++)
  121. {
  122. console.log("Number: ", i)
  123. }
  124. */
  125.  
  126. /*
  127. Using a Loop to output all the items in a Array
  128. var myList = ['apples', 'oranges', 'bananas'];
  129.  
  130. for (var i = 0; i < myList.length; i++)
  131. {
  132. alert('I have ' + myList[i]);
  133. }
  134. */
  135.  
  136. /* NOTES */
  137. // an Array is a list of items
  138. // developers in general count from 0
  139. // functions can be treated like variables due to the way Javascript works
  140. // arrays can store ANYTHING
  141. /*
  142. console.log() prints whatever is in there to the console
  143. it's basically what you use to print stuff and test things out
  144. */
  145. /*
  146. Loops are ways of looping through things over and over again
  147. There are 3 types of loops: For, While, and Do
  148. The only difference between the Do loop and the While loop is that
  149. the control is at the bottom of Do and for While it's at the top
  150. */
  151. -----------------------------------------------------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment