Programming tests and exercises


Online JavaScript interpreter that can be used to try out JavaScript examples:

Online JavaScript Interpreter by Peter Jipsen, Chapman University (January 2013).
http://math.chapman.edu/~jipsen/js/ (2020-11-19)

Note: If the link above does not work for some reason, use the link below.


Important warning: When answering to the questions do not use unnecessary spaces when entering JS codes in the input fields of the 'Answer' column below!


Question Answer Score
The following program displays the characters of a string variable one after the other. var x="1101"; var i=0; while(...) { writeln(x[i]); i=i+1; } writeln(); What should we write in the dotted space?
0
What will the following program display? var x="[abcdef]"; var s=""; for(var i=1;i<x.length-1;i++) { s=s+x[i]; } writeln(s);
0
The following program displays the string xyz on the screen. var x="..."; var s=""; for(var i=0;i<x.length;i++) { s=x[i]+s; } writeln(s); What should we write in the dotted space?
0
What will the following program display? var h=1; for(var i=1;i<4;i++) { h*=2; } writeln(h);
0
What will the following program display? var x="1011"; var d=0, h=8; for(var i=0;i<x.length;i++) { if(x[i]=="1") { d+=h; } h/=2; } writeln(d);
0
What will the following program display? var x="1011"; var d=0, h=1/2; for(var i=0;i<x.length;i++) { if(x[i]=="1") { d+=h; } h/=2; } writeln(d);
0
What will the following program display? var x="abc123"; var s=""; for(var i=0;i<x.length;i++) { switch(x[i]) { case "a": s=s+"A"; break; case "b": s=s+"B"; break; case "c": s=s+"C"; break; default: s=s+x[i]; } } writeln(s);
0
What will the following program display? var x="123"; var y="456"; var z=x+"+"+y; writeln(z);
0
What will the following program display? var x="123"; var y=456; var z=parseInt(x)+y; writeln(z);
0
What will the following program display? var j=40, s=""; if(j<=20) { s="bad"; } else if(j<=30) { s="good"; } else { s="excellent" } if(j>38) { s+="+" } writeln(s);
0
What do we need to write in the dotted space for the program to work correctly? var x=3; if(...) { writeln(x+" even"); } else { writeln(x+" odd"); }
0
Let's define the function f(x) as follows: function f(x) { var b=""; while(x>0) { if(x%2==1) { b="1"+b; x=x-1; } else { b="0"+b; } x=x/2; } return b; } What value will the function return in the case of f(13)?
0
What will the following program display? var b="10" var i=b.length; while(i<4) { b="0"+b; i=i+1; } writeln(b);
0
What will the following program display? var x=7, s="James Bond"; if(x<10) { s="00"+x; } else if(x<100) { s="0"+x; } else { s=""+x; } writeln(s);
0
What should we enter in the dotted space so that the program displays a 4-bit long binary number? var x="1" while(x.length...) { x="0"+x; } writeln(x);
0
Let us define the function g(x) as follows: function g(x) { var xc=""; for(var i=0;i<x.length;i++) { if(x[i]=="1") { xc=xc+"0"; } else { xc=xc+"1"; } } return xc; } What value will the function return in the case of g("0111")?
0
The following program displays 2 raised to the power 'n' (where n>0). var k=1,n=3; var i=1; while(i<=n) { ...*2; i=i+1; } writeln(k); What should we write in the dotted space?
0
The function below calculates the sum of the first 'n' natural numbers. function h(n) { var k=1, sum=0; for(var i=1;i<=n;i++) { sum=sum+k; k=k+1; } ... } What should we write in the dotted space?
0
Solved questions: 0
Total score: 0


Boda István, 2022-24.