+ 3
What is the error?
14 Answers
+ 4
What do you really want this code to do.
+ 2
Maybe .
+ 2
You have two main mistakes, and a messy code (need to reorder instructions):
+ you write 'ouput' instead of 'output' in the id attribute of your html <div>
+ your 'for' loop is wrong, so the function never end (index error break execution), by testing if 'x' is less or equal to array length (need to be strictly less)...
Fixed code:
https://code.sololearn.com/Wj0gAXH431Xz/?ref=app
+ 1
the syntax missed ;
and the varibels on line 16 its out of the local scope of the first function. so you need cut and paste the varibele in local scop this issuse your problem .
+ 1
I corrected it :-
https://code.sololearn.com/WpXpQRrXgbGJ/?ref=app
+ 1
I added one line .
You didn't wrote that .
+ 1
Compare it that's not the same .
0
window.onload=function(){
var code,output,n=0;
function chr(m){ return String.fromCharCode(97 + m);}
function compile(){
for(var x=0;x<=code.length;x++){
if(code[x]=="+"){
++n;
}
else if(code[x]=="-"){
--n;
}
else{
n=chr(n);
}
}
output.innerHTML=n;
code=document.getElementById("code").value;
output=document.getElementById("output");
compile();
}
}
you need learn global and local scope with function.
now its work.
0
Errors inform us of a messaging, which is something wrong.
0
hhh ok you are corrected it :) not me
0
look at first comment bro
0
ok but for this error its same same :)
0
@atikrant
the code still doesn't didn't compile
0
the function is inside the name itself