Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. // LOOPS
  12. /* Loops are used for running code multiple times. we can loop over forward and backwards
  13. through arrays and objects. There are a few different types of loops, such as::
  14. FOR LOOP -- loops through CODE BLOCK
  15. FOR/IN LOOP -- loops through the properties of an OBJECT
  16. WHILE LOOP -- loops through code while coded conditions are TRUE
  17. DO/WHILE -- ALSO loops through code while coded conditions are TRUE
  18. */
  19. //heres a few examples
  20.  
  21. var quote = "";
  22.  
  23. for (var i = 0; i < 10; i++) {
  24. // var i = 0 shows where we will start with our loop
  25. //i < 10 shows how long the loop will loop, or where we will stop our loop
  26. //i++ is our increment, it shows us the count we will do as the loop occurs
  27. quote += i;
  28. }
  29. console.log(quote);
  30.  
  31. //LOOPING FORWARDS AND BACKWARDS THROUGH AN ARRAY
  32. // FOR-IN LOOPS
  33. //here's how you loop through objects
  34.  
  35. var laptop = { // first, we create an pbject
  36. color: "white",
  37. size: 'small',
  38. graphics: 'good',
  39. battery: 'great',
  40. type: 'lenovo',
  41. age: 'few munths',
  42. stickers: 'none'
  43. }
  44.  
  45. for (var key in laptop) { //this says that for every key in the object laptop --
  46. console.log(laptop[key]); // log the laptop properties
  47. }
  48. var ki = Object.keys(laptop);// converts laptop object to an array
  49. console.log(ki); // logs the object's properties in an array
  50. console.log(ki.reverse());// reverses the objects properties
  51.  
  52. //WHILE LOOP
  53. //the while loop states to do a particular code block while a condition is true
  54. var whippin = -5
  55. while (whippin < 10) {
  56. console.log(whippin);
  57. whippin++;
  58. }
  59. console.log(whippin);
  60. </script>
  61.  
  62.  
  63.  
  64. <script id="jsbin-source-javascript" type="text/javascript">// LOOPS
  65. /* Loops are used for running code multiple times. we can loop over forward and backwards
  66. through arrays and objects. There are a few different types of loops, such as::
  67. FOR LOOP -- loops through CODE BLOCK
  68. FOR/IN LOOP -- loops through the properties of an OBJECT
  69. WHILE LOOP -- loops through code while coded conditions are TRUE
  70. DO/WHILE -- ALSO loops through code while coded conditions are TRUE
  71. */
  72. //heres a few examples
  73.  
  74. var quote = "";
  75.  
  76. for (var i = 0; i < 10; i++) {
  77. // var i = 0 shows where we will start with our loop
  78. //i < 10 shows how long the loop will loop, or where we will stop our loop
  79. //i++ is our increment, it shows us the count we will do as the loop occurs
  80. quote += i;
  81. }
  82. console.log(quote);
  83.  
  84. //LOOPING FORWARDS AND BACKWARDS THROUGH AN ARRAY
  85. // FOR-IN LOOPS
  86. //here's how you loop through objects
  87.  
  88. var laptop = { // first, we create an pbject
  89. color: "white",
  90. size: 'small',
  91. graphics: 'good',
  92. battery: 'great',
  93. type: 'lenovo',
  94. age: 'few munths',
  95. stickers: 'none'
  96. }
  97.  
  98. for (var key in laptop) { //this says that for every key in the object laptop --
  99. console.log(laptop[key]); // log the laptop properties
  100. }
  101. var ki = Object.keys(laptop);// converts laptop object to an array
  102. console.log(ki); // logs the object's properties in an array
  103. console.log(ki.reverse());// reverses the objects properties
  104.  
  105. //WHILE LOOP
  106. //the while loop states to do a particular code block while a condition is true
  107. var whippin = -5
  108. while (whippin < 10) {
  109. console.log(whippin);
  110. whippin++;
  111. }
  112. console.log(whippin);</script></body>
  113. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement