+ 2
Javascript Verification practice
Hi, I'm at the Verification practice and I'm stuck, because in Javascript I can't create userinput based on what I've learned so far, because the error code refers to the fact that this is not a valid Javascript command… let pin = 1345; let userInput=prompt("Enter pin"); // log "Success" to the console if user input matches 1345 if(pin===1345) { console.log("Success"); } // log "Fail" if user input doesn't match the given pin else{ console.log("Fail"); }
17 Antworten
+ 5
the current version is NOT supposed to get input. "pin" is already given. do not modify it; do not read user input.
compare pin to 1345 for equality.
+ 3
maybe you need to convert the input to a Number.
also, you should be comparing userInput with pin. not pin to 1345.
+ 3
the variable "pin" hold the "input". you are not supposed to use "prompt()". do NOT change what is stored in "pin".
also, your comparison doesn't follow the instructions. it should only output "Success" when the pin matches exactly 1345, not when the number is smaller or equal.
+ 3
this is a practice in the course. the course practice already defines pin. adding input at this point is confusing.
+ 3
Neverland Jimmy
prompt() is used to get user input in javascript if it's used in a web page. it's part of the web API.
// works in web code, not in NodeJS.
let userInput = prompt();
in that Sololearn exercise, NodeJS is used.
it doesn't have prompt(). you get user input using readLine(). I think it's an interface Sololearn defined internally for the exercises. it's easy to use, but you can't use it on NodeJS codebits...
// use this in the exercise
let userInput = readLine();
the rest of the code is the same
if(userInput === pin){
....
if you want something that can also work in NodeJS codebits, Mila's code is what you want.
I modified it a bit so it's simpler to understand.
https://sololearn.com/compiler-playground/c3LE46312QQk/?ref=app
+ 2
Neverland Jimmy, Sololearn doesn't support "prompt". You need to use "readline".
https://sololearn.com/compiler-playground/cShz2ikf9hdu/?ref=app
And you need write (Number(userinput)==pin) in if block.
+ 2
Lisa,
It didn't let me go any further because of the input, after I modified it based on Bob_Li's advice, after that there was no problem with the input. Nevertheless, I believe you, because I don't have any programming knowledge, only what I'm learning here, I started with Javascript.
+ 2
https://sololearn.com/compiler-playground/cShz2ikf9hdu/?ref=app - this is a correct code.
+ 2
Neverland Jimmy, I already wrote my correct code above before. I haven't tried the "JavaScript" course in Sololearn yet. You should try the course "JavaScript Intermediate" after you have completed the basic course. But how to connect modules and libraries - they will not teach this in the lesson. You need searching this information yourself. Stackoverflow is a great website, and I recommend it for you.
+ 1
You are a genius! Thank you!
The solution:
let pin = 1345;
let userInput=Number();
// log "Success" to the console if user input matches 1345
if(pin<=Number()) {
console.log("Success");
}
// log "Fail" if user input doesn't match the given pin
else{
console.log("Fail");
}
+ 1
Neverland Jimmy
I didn't actually revisit the exercise. I just extrapolated on your code.
too lazy to doublecheck 😅 . my bad.
listen to Lisa and Mila.
Sololearn lessons expect certain protocols and results.
Although the code might work, it would still fail the test if it's incompatible with the automated testing.
+ 1
If it's not a big request, can someone describe how the code would look correctly? It would be a huge help in learning!
+ 1
Thank you very much Mila! This seems difficult to me and I would just like to know, how can someone who learns exclusively with Sololearn solve this task with the knowledge they have learned based on the lessons learned so far?🙄
+ 1
Lisa, Sololearn SUPPORTS Readline input. You can try my code here.
+ 1
Lisa, If I change it to the version without userInput, it will let me pass the test, but when I click on the test, the "input" field will remain empty and as you wrote, it will only be an output success. Could you describe your version? I'm very curious about it!
0
В чем проблема?