Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. (1.) Which of the following are valid arrays (Answer all that apply)
  2.  
  3. ```javascript
  4. const A = ["Harder", "Better", "Faster", "Stronger"];
  5. const B = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89];
  6. const C = [
  7. "Urban Chestnut",
  8. 2009,
  9. "4Hands",
  10. 2011,
  11. "Rockwell",
  12. 2018
  13. ];
  14. const D = [false, 0, "F", true, 1, "T"];
  15. ```
  16.  
  17. <br>
  18.  
  19. (1-BONUS.) This a valid Array? true / false
  20.  
  21. ```javascript
  22. const E = [
  23. true,
  24. "HINT: arrays can contain any data type.",
  25. undefined,
  26. function () { alert("Hello World"); },
  27. null,
  28. { name: "Porky Pig", phrase: "That's All Folks!" },
  29. ];
  30. ```
  31.  
  32. <br>
  33.  
  34. (2.) What is the value of `directions` when it is logged?
  35.  
  36. ```javascript
  37. const directions = ["North", "East", "South", "West"];
  38. directions.pop();
  39. directions.shift();
  40. directions.push("Left");
  41. directions.unshift("Up");
  42.  
  43. console.log(directions);
  44. ```
  45.  
  46. <br>
  47.  
  48. (3.) What is the value of `allTraits` when it is logged?
  49. <br>(3-B.) What is the value of `characterTraits` when it is logged?
  50. <br>(3-C.) Why are these the same OR Why are these different?
  51.  
  52. ```javascript
  53. const characterTraits = [
  54. "Trustworthy",
  55. "Loyal",
  56. "Helpful",
  57. "Friendly",
  58. "Courteous"
  59. ];
  60.  
  61. const betterTraits = [
  62. "honest and fair",
  63. "friendly and helpful",
  64. "considerate and caring",
  65. "courageous and strong"
  66. ];
  67.  
  68. const allTraits = characterTraits.concat(betterTraits);
  69. console.log(characterTraits, allTraits);
  70. ```
  71.  
  72. <br>
  73.  
  74. (4.) Fill in the blanks to make the code work:
  75.  
  76. ```javascript
  77. const pets = [
  78. 'Dog',
  79. 'Cat',
  80. 'Bear',
  81. 'Bearded Dragon',
  82. 'Frilled Dragon',
  83. 'Komodo Dragon',
  84. 'Bunny',
  85. 'Bird'
  86. ];
  87.  
  88. const dragons = pets.slice( _____ , _____ );
  89. console.log(dragons);
  90. // dragons should return ['Bearded Dragon', 'Frilled Dragon', 'Komodo Dragon']
  91. ```
  92.  
  93. <br>
  94.  
  95. (4-B.) Log the name of your favorite pet by accessing it from the array
  96.  
  97. ```javascript
  98. const pets = [
  99. 'Dog',
  100. 'Cat',
  101. 'Bear',
  102. 'Bearded Dragon',
  103. 'Frilled Dragon',
  104. 'Komodo Dragon',
  105. 'Bunny',
  106. 'Bird'
  107. ];
  108. console.log(`My favorite pet is a ${ _____ }`);
  109. ```
  110.  
  111. <br>
  112.  
  113. (5.) What are the logged values?
  114.  
  115. ```javascript
  116. const characters = [" ", "A", "B", "C", "D", "E", "F", "G"];
  117.  
  118. const BIndex = characters.indexOf("B");
  119. const FIndex = characters.indexOf("F");
  120. const hasPercentSign = characters.includes("%");
  121. const mysteryValue = characters.push("H");
  122.  
  123. console.log(BIndex, FIndex, hasPercentSign, mysteryValue);
  124. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement