Even after doing the above, carrinho
will be an empty object {}
as for it to be filled, the criarCarrinho()
should run, but it will not run at all because of if (typeof carrinho === "undefined")
in the checarCarrinhoExiste()
function. This is because carrinoho
will either have an {}
object or whatever was saved in localstorage
when the load()
function runs and hence it's type will not be undefined, Hence, in addition to declaring carrinho
in the global scope, change the above IF condition to if (typeof carrinho !== "undefined")
and your code should work now as you intended.
Try and let us know if it works. All the best!