Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - Even Numbers Challenges

 

Take an array of numbers called "numbers" place a random mix even and odd numbers in it.

const stars = [1,2,3,4,5,6,7,8];

Now, using .map(), take the contents of the numbers and call a function which builds some html for the UI for each element in the array . Don't use a for loop.... use map(). Something like....

2
4
6
etc...

<div>2</div>
<div>4</div>
<div>6</div>
<div>etc...</div>


// solution
let solutionHtml = "";
const numbers = [1,2,3,4,5,6,7,8];

// this receives each element of the array and we will call it 'number'
const BuildHtml = (number) =>
{
    if (number % 2 == 0)
    {
        solutionHtml += `<div class="text-white">${number}</div>`;
    }
};

// build html
numbers.map(BuildHtml);
$("#DemoContainer").html(solutionHtml);