Created
November 30, 2022 18:42
-
-
Save elGuille-info/2543357b8a11fdb9e14080a458fb448c to your computer and use it in GitHub Desktop.
Manipulación de arrays en JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Del ejemplo de [Active learning: Printing those products]( | |
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Arrays?qs=arrays#active_learning_printing_those_products) | |
*/ | |
//const list = document.querySelector('.output ul'); | |
//const totalBox = document.querySelector('.output p'); | |
let total = 0; | |
//list.innerHTML = ''; | |
//totalBox.textContent = ''; | |
const products = [ | |
'Underpants:6.99', | |
'Socks:5.99', | |
'T-shirt:14.99', | |
'Trousers:31.99', | |
'Shoes:23.99', | |
]; | |
//const listItem = []; | |
console.log("Los productos son:") | |
for (const product of products) { | |
const subArray = product.split(':'); | |
const name = subArray[0]; | |
const price = Number(subArray[1]); | |
total += price; | |
const itemText = `${name} — $${price}`; | |
//const listItem = document.createElement('li'); | |
//listItem.textContent = itemText; | |
//list.appendChild(listItem); | |
//listItem.push(itemText); | |
console.log(itemText); | |
} | |
console.log(); | |
//totalBox.textContent = `Total: $${total.toFixed(2)}`; | |
console.log( `Total: $${total.toFixed(2)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment