I'm trying to learn javascript here and I have an assignment, I have to: ''Write the makeStickers function that accepts the detailsCount integer and the robotPart string. The function returns an array of strings in the following format: {{robotPart}} detail #{{n}} (for example, Hand detail #1).
For example:
makeStickers(3, 'Body'); // ['Body detail #1', 'Body detail #2', 'Body detail #3'] makeStickers(4, 'Head'); // ['Head detail #1', 'Head detail #2', 'Head detail #3', 'Head detail #4'] makeStickers(0, 'Foot'); // []''
function makeStickers(detailsCount, robotPart) {
// write code here
}
I wrote the following function, but for some reason it always gives me just robot part #2, without any other iteration. Please help.
function makeStickers(detailsCount, robotPart) {
let arr = [];
for(let i = 1; i <= detailsCount; i++){
arr = [`${robotPart} detail #${arr.push(i)}`]
};
return arr
};