benjaminvr

Codecademy - Secret message (array methods exercise)

Jul 15th, 2021
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let secretMessage = ['Learning', 'is', 'not', 'about', 'what', 'you', 'get', 'easily', 'the', 'first', 'time,', 'it', 'is', 'about', 'what', 'you', 'can', 'figure', 'out.', '-2015,', 'Chris', 'Pine,', 'Learn', 'JavaScript'];
  2.  
  3.  
  4. // Use an array method to remove the last string of the array secretMessage.
  5. secretMessage.pop();
  6.  
  7. // Great! You can check your work by logging the .length of the array.
  8. // At this point, the length should be 1 less than the original length.
  9. console.log(secretMessage.length);
  10.  
  11. //Use an array method to add the words to and Program as separate strings to the end of the secretMessage array.
  12. secretMessage.push('to');
  13. secretMessage.push('Program');
  14.  
  15. // Change the word easily to the word right by accessing the index and replacing it.
  16. secretMessage[7] = 'right';
  17.  
  18. // Use an array method to remove the first string of the array.
  19. secretMessage.shift();
  20.  
  21. // Use an array method to add the string Programming to the beginning of the array.
  22. secretMessage.unshift('Programming');
  23.  
  24. // Use an array method to remove the strings get, right, the, first, time,, and replace them with the single string know,.
  25. secretMessage[10] = 'know,';
  26.  
  27. // Starts at position 6, removes 4
  28. secretMessage.splice(6,4);
  29.  
  30. // On one line, use console.log() and .join() to print the secret message as a sentence.
  31. console.log(secretMessage.join(" "));
  32.  
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment