Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 754 Bytes

Add property to every object in array.md

File metadata and controls

28 lines (21 loc) · 754 Bytes

Description:

Your task is to add a new property usersAnswer to every object in the array questions. The value of usersAnswer should be set to null. The solution should work for array of any length.

After adding the property the result should be:

Examples (input --> output):

var questions = [{
    question: "What's the currency of the USA?",
    choices: ["US dollar", "Ruble", "Horses", "Gold"],
    corAnswer: 0,
    usersAnswer: null
}, {
    question: "Where was the American Declaration of Independence signed?",
    choices: ["Philadelphia", "At the bottom", "Frankie's pub", "China"],
    corAnswer: 0,
    usersAnswer: null
}];

Solution:

questions.forEach(question => question['usersAnswer'] = null);