Skip to content

Instantly share code, notes, and snippets.

@nicobytes
Created March 23, 2022 23:09
Show Gist options
  • Save nicobytes/bd18fbe87c037a10faa3296ea3992639 to your computer and use it in GitHub Desktop.
Save nicobytes/bd18fbe87c037a10faa3296ea3992639 to your computer and use it in GitHub Desktop.
example
(()=> {
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