<p>Complete each challenge listed below by editing the code inside the JS section of this Codepen. Place your code in the areas indicated by the comments.</p>
<p>Use the developer console or the Codepen console (with the Console button provided by Codepen at the bottom left of your screen) to see console.log messages. Be aware that the Codepen console does not show all error messages, so if you're running into an error, try opening your browser's built-in developer console. </p>
<h3>Challenge 1</h3>
<ul>
<li>Use the <strong>map</strong> method on the numbers array given at line 2 to add 5 to each number and put the results into a new array. The code has been started for you at line 3.
</li>
</ul>
<h3>Challenge 2</h3>
<ul>
<li>Use the map method on the same numbers array to turn it into an array of strings, and add a colon and a space after each number. The code has been started for you at line 7. </li>
</ul>
<h3>Challenge 3</h3>
<ul>
<li>Use the map method on the words array on line 13 to remove the "s" from the end of each word. The code has been started for you in line 14. <strong>Hint:</strong> Research the use of the String.slice() method to remove the final letter from a string. There are other String methods that could also be used.</li>
</ul>
<h3>Challenge 4</h3>
<ul>
<li>Use the map method on the words array from line 13 to return an array with just the first letter of each word. The code has been started for you in line 19.</li>
</ul>
<h3>Bonus Challenge</h3>
<ul>
<li>Use the map method on the words array to return an array with just the first letter of each word capitalized (along with the rest of the word in lower case)</li>
</ul>
<h3>Additional Resources</h3>
<ul>
<li><a href="https://www.w3schools.com/jsref/jsref_map.asp" target="_blank">W3Schools - Array.Map()</a></li>
<li><a href="http://javascript.info/array-methods#map" target="_blank">JavaScript.info - Array methods - map</a></li>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" target="_blank">MDN - Array Map</a></li>
<li><a href="https://www.w3schools.com/jsref/jsref_slice_array.asp" target="_blank">W3Schools - Array.slice()</a></li>
</ul>
body {
font-family: "Oxygen", sans-serif;
margin: 1rem;
}
// 1
const numbers = [1, 1, 2, 3, 5];
const numbersAddFive = numbers.map(num => num +5);
// The below line should console.log: [6, 6, 7, 8, 10]
console.log(numbersAddFive);
// 2 - uncomment the lines that start with "const" and "console.log"
const numbersReformatted = numbers.map(num => `${num}: `);
// The below line should console.log: ["1: ", "1: ", "2: ", "3: ", "5: "]
console.log(numbersReformatted);
// 3
const words = ["planes", "trains", "automobiles"];
const singularWords = words.map(word => word.slice(0, -1));
// The below line should console.log: ["plane", "train", "automobile"]
console.log(singularWords);
// 4:
const firstLetters = words.map(word => word[0]);
// The below line should console.log: ["p", "t", "a"]
console.log(firstLetters);
// Bonus:
const capitalizedWords = words.map(word => word.charAt(0).toUpperCase() + word.slice(1));
// The below line should console.log: ["Planes", "Trains", "Automobiles"]
console.log(capitalizedWords);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.