Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done #3236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

done #3236

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ <h1>Ironhack Cart</h1>
</td>
</tr>
<!-- Iteration 2: Add more products here -->
<tr class="product">
<td class="name">
<span>Ironhack Beach Towel</span>
</td>
<td class="price">$<span>12.50</span></td>
<td class="quantity">
<input type="number" value="0" min="0" placeholder="Quantity" />
</td>
<td class="subtotal">$<span>0</span></td>
<td class="action">
<button class="btn btn-remove">Remove</button>
</td>
</tr>
</tbody>
<tfoot>
<!-- <tr class="create-product">
Expand Down
23 changes: 23 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,43 @@ function updateSubtotal(product) {
console.log('Calculating subtotal, yey!');

//... your code goes here
const price = product.querySelector('.price span').innerText; // Seleccionamos Producto, con .innerText extraemos el texto, en este caso 25.00
const quantity = product.querySelector('.quantity input').value; // con .value obtenemos el valor actual del imput (quantity)
// Calculamos subtotal
let priceSubtotal = price * quantity;
// Obtenemos el elemento DOM del elemento <span> con la clase subtotal. y mostramos el precio en SubTotal
let subtotal = product.querySelector('.subtotal span');
subtotal.innerText =+ priceSubtotal;

return priceSubtotal;
}

function calculateAll() {
// code in the following two lines is added just for testing purposes.
// it runs when only iteration 1 is completed. at later point, it can be removed.
/*
const singleProduct = document.querySelector('.product');
updateSubtotal(singleProduct);
*/
// end of test

// ITERATION 2
//... your code goes here
const products = document.querySelectorAll('.product'); // Selecionamos todos los productos
let totalPrice = 0; // Inicializamos la variable
for (let i = 0; i < products.length; i++) { // Recorremos todos los elementos Products
// producto actual:
let updatedProduct= products[i];
// Actualización del subtotal y acumulación en total:
totalPrice += updateSubtotal(updatedProduct); // Llamamos a la función updateSubtotal
console.log(totalPrice);
}


// ITERATION 3
//... your code goes here
let total = document.querySelector('#total-value span'); // Obtenemos elemento con #total-value span
total.innerText = totalPrice; // Extraemos el precio total y lo mostramos en el elemento con #total-value span
}

// ITERATION 4
Expand Down