~prop
Coder
Hello.
I have a problem with my code in JS. I am trying to make new user by reading the input prompt (first function) and saving it into the local storage (second function) but it doesn't seem to work, once I open the project in live server by Visual Studio Code and try to make new user, it shows error in edge console and says that the "localStorage.setItem(...)" is undefined. I tried to change something or do the same thing in different ways but it still won't work out. Please help me. (There is "var" used in variable making, it is a school project and they thought us to use this but can you also say how to make this with "let"? )
Thanks for help, here is the code of JS, if needed, I will post the other files linked to it like HTML to find the solution.
I have a problem with my code in JS. I am trying to make new user by reading the input prompt (first function) and saving it into the local storage (second function) but it doesn't seem to work, once I open the project in live server by Visual Studio Code and try to make new user, it shows error in edge console and says that the "localStorage.setItem(...)" is undefined. I tried to change something or do the same thing in different ways but it still won't work out. Please help me. (There is "var" used in variable making, it is a school project and they thought us to use this but can you also say how to make this with "let"? )
Thanks for help, here is the code of JS, if needed, I will post the other files linked to it like HTML to find the solution.
JavaScript:
function newUser() {
var new_username = document.getElementById("username-field").value;
var new_password = document.getElementById("password-field").value;
if ((new_username == "" || new_password == "") || (new_username == "" && new_password == "")) {
alert("Neesi ievadījis vajadzīgos datus!");
}
else {
localStorage.setItem("username", new_username).value;
localStorage.setItem("password", new_password).value;
alert("Esi izveidojis jaunu lietotāju!");
}
}
function checkUser() {
var username = document.getElementById("username-field").value;
var password = document.getElementById("password-field").value;
var user = document.getElementById("username").value = localStorage.getItem("username");
var pass = document.getElementById("password").value = localStorage.getItem("password");
if (user == username) {
if (pass == password) {
console.log("Dati patiesi!")
window.location.replace("program.html");
}
}
else {
document.getElementById("notification").textContent = "Nepareizs lietotājvārds un/vai parole!";
}
}