+ 2
JavaScript - no output in if/else
Hey, I'm trying for longer than a hour now to fix the error. Why is my code incorrect? I need to output the string "vacation" if the input is == "August". This is my code. I tried it with the normal if (month = "August" but it didn't work, I tried it with ==, I even tried as you can see in the code now to convert it into a boolean and asked the code to give me the "vacation" text if the august var is the same like month.. I really don't know what's wrong here. Pls help me and explain where my mistake is. Thank you so much! var month = parseInt(readLine(), 10) var august = ("August"); if (august == month) { console.log("vacation"); }
6 Answers
+ 5
Dennis Lier
Don't parse input with int so remove parseInt from readLine()
Just do this:
var month = readLine();
if (month == 'August') {
}
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ lol it worked thank you. But what was my mistake? The input line with "var month" was prepared by sololearn. How should I handle the problem without changing the first line?
+ 1
Dennis Lier
There is no problem in your code, problem is in readymade code provided by Sololearn because in test cases there is String but they parse String in int using parseInt which is wrong.
+ 1
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ omg thank you so much you couldn't imagine how long I tried to understand why the code never worked. I thought I'm stupid
+ 1
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ I never thought that the given line could be wrong so I just tripple checked my code and tried to change it haha
0
Dennis Lier
First time I was also confused but then I saw the first line.