0

Why isn't if statement working even though no error

The code is Why isn't code working /* alert Don't ever mod this compiler please else you may get reported with mod in internet */ alert("UI coming soon") var text = prompt ("code input") text = text.split(" "); for(var i = 0; i < text.length; i++){ console.log(text[i]); console.log(output) var output = "<!-- Code covertion done as Ele to html by Ele compiler original -->" if (text[i] === "compile.Ele{") { var output = " <html>" } else if (text[i] === "}compile.Ele"){ var output = " </html>" } else{ var output = text[i] } document.write(output) } Plz help https://code.sololearn.com/Wb7Nvy5oLMwV/?ref=app

9th Sep 2022, 1:47 PM
heaker Gamer
5 Respostas
+ 1
And what are the inputs and outputs now? It re-ordered some things, you can see the tested input in the comments. https://code.sololearn.com/Wyway1YkiG19/?ref=app
9th Sep 2022, 3:20 PM
Lisa
Lisa - avatar
+ 5
I think one problem is with the curly brackets {} here if (text[i] === "compile.Ele{") { var output = " <html>" } else if (text[i] === "}compile.Ele"){ They seem to be in a random position after .Ele in the first line and before compile. In the third line.
9th Sep 2022, 1:59 PM
Ausgrindtube
Ausgrindtube - avatar
+ 3
What is the expected input? What is the expected output? Please give examples. Why do you re-declare "output" in the if-statement? People are more likely to test your code if you put it in a script on sololearn playground. That way it is more readable and people can actually run it.
9th Sep 2022, 1:57 PM
Lisa
Lisa - avatar
+ 2
Ok I'll upload code in Sololearn so you guys can test
9th Sep 2022, 3:00 PM
heaker Gamer
+ 2
The brackets are part of the string
9th Sep 2022, 3:02 PM
heaker Gamer