Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
Hi i am having a problem in java script with function and arrays

Print a shopping list Create a function called print Shopping List that take a list of products and print the items to the screen.

//
 shopping List = [
    { item Name : 'Bread', price : 11.00 },
    { item Name : 'Milk', price : 7.00 },
    { item Name : 'Cheese', price : 19.50 }
];
This should print:

Shopping list:
* Bread @ R11.00
* Milk @ R7.00
* Cheese @ R19.50
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

console.log('Shopping List:');
shoppingList.forEach(ele => {
console.log('*'+ele.ItemName+'@'+'R'+ele.price);
);

Hope this helps.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try the below code. Hope it helps.

const shoppingList = [{
    itemName: 'Bread',
    price: 11.00
  },
  {
    itemName: 'Milk',
    price: 7.00
  },
  {
    itemName: 'Cheese',
    price: 19.50
  }
];

const itemsHTML = shoppingList.map(item => (
  `<li>${item.itemName} @ R${item.price}</li>`
))

document.write(`<ul>${itemsHTML}</ul>`);

about 4 years ago · Juan Pablo Isaza Relatório

0

You can simply achieve it by creating a node in the HTML DOM and create the custom string by using template string.

Demo :

const shoppingList = [
    { itemName : 'Bread', price : 11.00 },
    { itemName : 'Milk', price : 7.00 },
    { itemName : 'Cheese', price : 19.50 }
];

shoppingList.forEach(item => {
  const node = document.createElement("li");
  const liNode = document.getElementById('priceList').appendChild(node);
  liNode.innerHTML = `${item.itemName} @ R${item.price}`
});
<ul id="priceList"></ul>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda