What’s wrong with this code? [solved] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What’s wrong with this code? [solved]

I tried to make a login page where you signup first and then login. If Username = input1 (do something); And so on. But it keep saying “script error” and I really can’t figure it out. Hope some of you can help me out :) https://code.sololearn.com/WYzE3ZQ2xatU/?ref=app

23rd Nov 2018, 12:15 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
3 Answers
+ 2
//cleaned up your JS, and fixed your error. I believe you were declaring variables in a function, and then trying to compare them to variables in another function. When variables are declared like this, in a function, they cannot be used outside of the function. So I have declared all 3 beforehand var try1, try2, try3; function Signup() { try3 = prompt("Name"); try1 = prompt("Username"); try2 = prompt("Password"); } function login() { var User = prompt("Username"); var Pass = prompt("Password"); if (User == try1 && Pass == try2) { alert("Succes") }else { alert("Something went wrong") } }
23rd Nov 2018, 1:06 AM
Jax
Jax - avatar
+ 1
thanks alot. i didnt notes that
23rd Nov 2018, 2:11 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
+ 1
notice
23rd Nov 2018, 2:11 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar