The aim of this skill test is to help you assess whether you've understood our Arrays article.
Note: To get help, read our Test your skills usage guide. You can also reach out to us using one of our communication channels.
First of all, we are giving you a fun, interactive arrays challenge created by our learning partner, Scrimba.
Watch the embedded scrim, and complete the task on the timeline (the little ghost icon) by following the instructions and editing the code. When you are done, you can resume watching the scrim to check how the teacher's solution matches up with yours.
Note: This task is somewhat of a stretch goal, given that it relies on JavaScript features you've not yet explicitly covered during the course. Give it your best shot, and search online for information on anything you are not sure about.
This task gives you some basic array practice:
myArray. The items can be anything you want — how about your favorite foods or bands?The starting point of the task looks like this (nothing is shown yet):
Here's the underlying code for this starting point:
// Add your code here
// Don't edit the code below here!
const section = document.querySelector("section");
const para1 = document.createElement("p");
para1.textContent = `Array: ${myArray}`;
section.appendChild(para1);The updated output should look like this:
Your finished JavaScript should look something like this:
const myArray = ["cats", "dogs", "chickens"];
myArray[0] = "horses";
myArray[1] = "pigs";
myArray.unshift("crocodiles");
// Don't edit the code below here!
// ...Now let's move on to another task. Here you are provided with a string to work with.
To complete the task:
+ characters in the process. Save the result in a variable called myArray.arrayLength.lastItem.The starting point of the task looks like this (nothing is shown yet):
Here's the underlying code for this starting point:
const myString = "Ryu+Ken+Chun-Li+Cammy+Guile+Sakura+Sagat+Juri";
// Add your code here
// Don't edit the code below here!
const section = document.querySelector("section");
const para1 = document.createElement("p");
para1.textContent = `Array: ${myArray}`;
const para2 = document.createElement("p");
para2.textContent = `The length of the array is ${arrayLength}.`;
const para3 = document.createElement("p");
para3.textContent = `The last item in the array is "${lastItem}".`;
section.appendChild(para1);
section.appendChild(para2);
section.appendChild(para3);The updated output should look like this:
Your finished JavaScript should look something like this:
const myString = "Ryu+Ken+Chun-Li+Cammy+Guile+Sakura+Sagat+Juri";
let myArray = myString.split("+");
let arrayLength = myArray.length;
let lastItem = myArray[arrayLength - 1];
// Don't edit the code below here!
// ...For this array task, we provide you with a starting array, and you will work in somewhat the opposite direction. You need to:
Ryu (0). Note that we don't teach how to do this in the Arrays article, so you'll have to do some research.myString, with a separator of "-".The starting point of the task looks like this (nothing is shown yet):
Here's the underlying code for this starting point:
const myArray = [
"Ryu",
"Ken",
"Chun-Li",
"Cammy",
"Guile",
"Sakura",
"Sagat",
"Juri",
];
// Add your code here
// Don't edit the code below here!
const section = document.querySelector("section");
const para1 = document.createElement("p");
para1.textContent = myString;
section.appendChild(para1);The updated output should look like this:
Your finished JavaScript should look something like this:
const myArray = [
"Ryu",
"Ken",
"Chun-Li",
"Cammy",
"Guile",
"Sakura",
"Sagat",
"Juri",
];
myArray.pop();
myArray.push("Zangief");
myArray.push("Ibuki");
myArray.forEach((element, index) => {
const newElement = `${element} (${index})`;
myArray[index] = newElement;
});
const myString = myArray.join(" - ");
// Don't edit the code below here!
// ...For this array task, we provide you with a starting array listing the names of some birds.
To complete the task:
"Eagles" item, and use that to remove the "Eagles" item.eBirds, that contains only birds from the original array whose names begin with the letter "E". Note that startsWith() is a great way to check whether a string starts with a given character.The starting point of the task looks like this (nothing is shown yet):
Here's the underlying code for this starting point:
const birds = ["Parrots", "Falcons", "Eagles", "Emus", "Caracaras", "Egrets"];
// Add your code here
// Don't edit the code below here!
const section = document.querySelector("section");
const para1 = document.createElement("p");
para1.textContent = eBirds;
section.appendChild(para1);The updated output should look like this:
Your finished JavaScript should look something like this:
const birds = ["Parrots", "Falcons", "Eagles", "Emus", "Caracaras", "Egrets"];
const eaglesIndex = birds.indexOf("Eagles");
birds.splice(eaglesIndex, 1);
function startsWithE(bird) {
return bird.startsWith("E");
}
const eBirds = birds.filter(startsWithE);
// Don't edit the code below here!
// ...