Advertisement
makispaiktis

Codecademy - 19th Exercise (Arrays in Javascript)

Dec 15th, 2019 (edited)
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. 1.
  4. Use an array method to remove the last string of the array secretMessage.
  5.  
  6. 2.
  7. Great! You can check your work by logging the .length of the array.
  8.  
  9. At this point, the length should be 1 less than the original length.
  10.  
  11. 3.
  12. Use an array method to add the words to and Program as separate strings to the end of the secretMessage array.
  13.  
  14. 4.
  15. Change the word easily to the word right by accessing the index and replacing it.
  16.  
  17. 5.
  18. Use an array method to remove the first string of the array.
  19.  
  20. 6.
  21. Use an array method to add the string Programming to the beginning of the array.
  22.  
  23. 7.
  24. Use an array method to remove the strings get, right, the, first, time,, and replace them with the single string know,.
  25.  
  26. Call .splice() like this:
  27.  
  28. array.splice(indexToStart, numberOfIndices, 'stringToAdd');
  29. You can read the documentation on MDN.
  30.  
  31. 8.
  32. On one line, use console.log() and .join() to print the secret message as a sentence.
  33.  
  34. Use console.log() and .join(' ') like this
  35.  
  36. console.log(array.join(' '));
  37. Programming is not about what you know, it is about what you can figure out. -2015, Chris Pine, Learn to Program
  38.  
  39. */
  40.  
  41. 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'];
  42.  
  43. let last = secretMessage.pop();
  44. secretMessage.push('to', 'Program');
  45. let index = secretMessage.indexOf('easily');
  46. secretMessage[index] = 'right';
  47. let first = secretMessage.shift();
  48. secretMessage.unshift('Programming');
  49. console.log(secretMessage);
  50. let index2 = secretMessage.indexOf('get');
  51. secretMessage.splice(index2, 5, 'know', 'well');
  52. console.log();
  53. console.log(secretMessage.join(' '));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement