Created
March 23, 2022 23:09
-
-
Save nicobytes/bd18fbe87c037a10faa3296ea3992639 to your computer and use it in GitHub Desktop.
example
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
(()=> { | |
const myCart = []; | |
const products = []; | |
const limit = 2; | |
async function getProducts() { | |
const rta = await fetch('http://api.escuelajs.co/api/v1/products', { | |
mehtod: 'GET' | |
}); | |
const data = await rta.parseJson(); | |
products.concat(data); | |
} | |
function getTotal() { | |
const total = 0; | |
for (const i = 0; i < products.length(); i++) { | |
total += products[i].prize; | |
} | |
return total; | |
} | |
function addProduct(index) { | |
if (getTotal <= limit) { | |
myCart.push(products[index]); | |
} | |
} | |
await getProducts(); | |
addProducto(1); | |
addProducto(2); | |
const total = getTotal(); | |
console.log(total); | |
const person = { | |
name: 'Nicolas', | |
lastName: 'Molina' | |
} | |
const rta = person + limit; | |
console.log(rta); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment