I'm currently learning JavaScript and I've encountered a challenge. I have a dictionary that I'd like to update whenever a button is clicked and the user enters some data in a prompt. However, for some reason, I am unable to successfully update the dictionary.
"use strict"
let views = {View1:"From localStorage"};
let btn = document.getElementById("myBtn")
btn.addEventListener("click",function(){
let vname = prompt("What is the name of the new view?")
views[vname] = vname + " 77"
})
let views_ser = JSON.stringify(views)
localStorage.setItem("views",views_ser);
let views_deser = JSON.parse(localStorage.getItem("views"))
for (let keys in views_deser){
document.write(keys + "<br>")
document.write(views_deser[keys]+ "<br>")
}
Appreciate any help on this. Thank you.