I've been working on coding a heads or tails system in JavaScript, but I've hit a roadblock. I am struggling to find a solution.
Here is what I have so far:
const userInput = prompt("Heads or Tails?");
const arr = [0, 0, 1, 1, 1, 0, 1, 0, 1];
arr["Result"] = "heads";
let headCount = 0, tailCount = 0;
for (let i = 0; i < arr.length; i++) {
if (arr["Result"] === "heads")
headCount += arr[i];
else
tailCount += arr[i];
}
alert("Heads: " + headCount + " " + "Tails: " + tailCount);
I'm struggling to figure out where I went wrong. Any insights or advice would be greatly appreciated.
Thank you