I'm trying to make 10PRINT in javascript but I'm getting an out-of-memory error.
it's supposed to output something like this:
///////\///\///\////////\\/\\///\\///
here is the code:
let st = []
let i = 0
let i2 = 0
while(i < 10)
{
while(i2 < 10)
{
if(Math.random() > 0.5)
{
st.push("/")
}else
{
st.push(" ⃥")
}
}
i2 = 0
console.log(st)
st = {}
}
can somebody tell me why it's not working?
i2 < 10ori < 10to be false? What is the purpose ofi2 = 0inside the loop or ofst = {}? Read the documentation:while,Array, What’s the difference between “{}” and “[]” while declaring a JavaScript array?. The entire code can be replaced byconsole.log(Array.from({ length: 10 }, () => (Math.random() < 0.5 ? "/" : "\\")).join(""));. Why do you have nested loops?