Hello! So i’m trying to randomly save buttons to a localstorage array. When I refresh the page, the button values in the array are changed into objects. I was seeing if someone knows the cause of this. Thanks!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memory Game</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<button id = "red">Red</button>
<button id ="green">Green</button>
<button id ="blue">Blue</button>
<button id ="orange">Orange</button>
<script src="app.js"></script>
</body>
</html>
const gameDecision = "Computer phase";
const buttonArray = JSON.parse(localStorage.getItem("buttonArray")) || [];
const playerButtonArray = [];
const redButton = document.getElementById("red");
const greenButton = document.getElementById("green");
const blueButton = document.getElementById("blue");
const orangeButton = document.getElementById("orange");
function buttons(set){
redButton.addEventListener("click", e =>{
console.log("yes")
})
greenButton.addEventListener("click", e =>{
console.log("yes")
})
if(gameDecision === "Computer phase"){
set = Math.floor(Math.random() * 3);
} if(set === 0){
buttonArray.push(redButton);
} else if(set === 1){
buttonArray.push(greenButton);
}
updateLocalStorage()
}
buttons()
function updateLocalStorage(){
localStorage.setItem("buttonArray", JSON.stringify(buttonArray));
}
console.log(buttonArray)