The aim of this skill test is to assess whether you've understood our Looping code article.
We haven't explicitly taught this yet in the course, but you'll have seen some examples that make use of it, and we'd like you to do some research into what DOM APIs you need to successfully answer the questions. A good starting place is our Manipulating documents tutorial.
In our first looping task we want you to start by creating a simple loop that goes through all the items in the provided
myArray and prints them out on the screen inside list items (i.e.,
<li> elements), which are appended to the provided
In this next task, we want you to write a simple program that, given a name, searches an array of objects containing names and phone numbers (
phonebook) and, if it finds the name, outputs the name and phone number into the paragraph (
para) and then exits the loop before it has run its course.
You are given three variables to begin with:
name— contains a name to search for
para— contains a reference to a paragraph, which will be used to report the results
phonebook- contains the phonebook entries to search.
You should use a type of loop that you've not used in the previous task.
In this final task, you are provided with the following:
i— starts off with a value of 500; intended to be used as an iterator.
para— contains a reference to a paragraph, which will be used to report the results.
isPrime()— a function that, when passed a number, returns
trueif the number is a prime number, and
You need to use a loop to go through the numbers 2 to 500 backwards (1 is not counted as a prime number), and run the provided
isPrime() function on them. For each number that isn't a prime number, continue on to the next loop iteration. For each one that is a prime number, add it to the paragraph's
textContent along with some kind of separator.
You should use a type of loop that you've not used in the previous two tasks.