Advertisement
Crevice

Loops Practice

Nov 11th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1.  
  2. // For Loops
  3. // Documentation:
  4. // W3: https://www.w3schools.com/js/js_loop_for.asp
  5. // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for
  6. // Create a `for` loop which runs 10 times, and console logs out the index for each iteration
  7. // Create a `for` loop which runs 10 times, and increments the index by two each iteration
  8. // Also console logs the index for each iteration
  9. // Create a `for` loop which runs 100 times, and console logs out only the indexes which are
  10. // multiples of 3
  11. // Create a `for` loop which runs 100 times, and console logs out only the indexes which are
  12. // even numbers
  13. // Create a `for` loop which runs 100 times, and console logs out only the indexes which are
  14. // odd numbers
  15. // Create a `for` loop which runs 100 times, and console logs out only the indexes which are
  16. // multiples of 5
  17. // Create a `for` loop which runs 25 times, and increments the index by three each iteration
  18. // Also console logs out the index - 30, but only for values which will result in a positive integer
  19. // for example if index is 20, you cannot subtract 30 because the result would be -10
  20. // Create a `for` loop which runs 100 times in reverse, and console logs "time till explosion" along
  21. // with the index number
  22. // Create a `for` loop which runs 50 times in reverse, and decrements the index by 4, and console logs
  23. // "turbo modes engages in " along with the index number
  24. // While loops
  25. // Documentation:
  26. // W3: https://www.w3schools.com/js/js_loop_while.asp
  27. // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while
  28. // Create a `while` loop which runs 10 times, and console logs out the index for each iteration
  29. // Create a `while` loop which runs 10 times, and increments the index by two each iteration
  30. // Also console logs the index for each iteration
  31. // Create a `while` loop which runs 100 times, and console logs out only the indexes which are
  32. // multiples of 3
  33. // Create a `while` loop which runs 100 times, and console logs out only the indexes which are
  34. // even numbers
  35. // Create a `while` loop which runs 100 times, and console logs out only the indexes which are
  36. // odd numbers
  37. // Create a `while` loop which runs 100 times, and console logs out only the indexes which are
  38. // multiples of 5
  39. // Create a `while` loop which runs 25 times, and increments the index by three each iteration
  40. // Also console logs out the index - 30, but only for values which will result in a positive integer
  41. // for example if index is 20, you cannot subtract 30 because the result would be -10
  42. // Create a `while` loop which runs 100 times in reverse, and console logs "time till explosion" along
  43. // with the index number
  44. // Create a `while` loop which runs 50 times in reverse, and decrements the index by 4, and console logs
  45. // "turbo modes engages in " along with the index number
  46. // For In Loops
  47. // The following For In loops will make use of this loop Object below
  48. // Documentation:
  49. // W3: https://www.w3schools.com/jsref/jsref_forin.asp
  50. // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in
  51. var loopObject = {
  52. index_1: 1,
  53. index_2: 2,
  54. index_3: 3,
  55. index_4: 4,
  56. index_5: 5,
  57. index_6: 6,
  58. index_7: 7,
  59. index_8: 8,
  60. index_9: 9,
  61. index_10: 10,
  62. }
  63. // Create a `for in` loop which loops through the `loopObject` and
  64. // console logs out each of the property names
  65. // Create a `for in` loop which loops through the `loopObject` and
  66. // console logs out just the values for each of the property names
  67. // Create a `for in` loop which loops through the `loopObject` and
  68. // console logs out the following string for each property with the
  69. // properties and values concatenated into it
  70. // "The property name is [property name] and the value is [property value]"
  71. // The following For In loops will make use of this loop Object below
  72. var person = {
  73. name: "jimmy",
  74. age: 32,
  75. dog: false,
  76. cat: true,
  77. favorite_food: 'sushi',
  78. favorite_number: 42,
  79. favorite_movie: "Tron: Legacy",
  80. greatest_fear: "clowns",
  81. favorite_song: "",
  82. hours_of_sleep: null
  83. }
  84. // Create a `for in` loop which loops through the `person` object and
  85. // console logs out only the property values which are `strings`
  86. // Create a `for in` loop which loops through the `person` object and
  87. // console logs out only the property values which are `falsy`
  88. // Create a `for in` loop which loops through the `person` object and
  89. // console logs out only the property values which are `numbers`
  90. // Create a `for in` loop which loops through the `person` object and
  91. // console logs out only the properties which contain `falsy` values
  92. // Create a `for in` loop which loops through the `person` object and
  93. // console logs out only the properties which contain `number` values
  94. // Create a `for in` loop which loops through the `person` object and
  95. // console logs out only the properties which contain `string` values
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement