My entry to js quiz.

in javascriptquiz •  4 years ago  (edited)

QUESTIONS :
Q1) Give the Output of the following javasript code , also provide the reason for your answe.

window.alert(window.alert("hello"));

Ans: Here first a pop up window alerts comes wit a message "hello" because of the statement written in the first parentheses of window.alert(). After clicking ok button it will show another pop alert with message undefined.

window.alert( );
Ans: Display alert box with no message and a ok button.

window.alert(console.log("@double-u has more than 2700000 BP"));
Ans: Display alert box with undefined message.
And if we go and check the console output by right click and and going in inspect element and opting console. Output will be @double-u has more 2700000

var x = 1;
console.log("window.alert( x++ )");
Ans: output in console will be window.alert(x++)

console.log(@afrog is attending the quiz);
Ans:syntax error because @afrog is attending the quiz should be written in double quotes like "@afrog is attending the quiz"

({
script(here i have removed <> from both side of script)
var x = 20 ;
for(i=0; i<x ; i++)
{
console.log("x is now " + x );
}

})(I have inserted some extra symbol because while posting it is showing that i can not use html element)
Ans: output:"x is now 20" 20 times on console.

what will be the output if in question number 6 after console.log("x is now " + x ); the next line of code is added as :
a) x--;
b) x= x-20;
c) x=x-i;
d) x= x++ + --x; // @jacobgadikian this is for all the developers here , It is challenge for all.
Ans 7:a)the output in console will be :x is now 20, x is now 19 and so on till "x is now 11" after that i value will become more then x mean condition false loop will be terminated.
b) output: x is now 20, after that i value will be mote then x and for loop get terminated.
c) output: x is now 20
x is now 20
x is now 19
x is now 17
x is now 14
x is now 10
I can not attempt rest of the question because that requires laptop which I am unable to access for somedays

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BLURT!
Sort Order:  

ok you are correct for most of the part but i might have forgottento close the script tag.

I recommend you to assume that script tag is closed and now tell the outputs.

Thank You.

  ·  4 years ago  ·  

Ans 6:It will print "x is now 20" 20 times on console
Ans 7:a)the output in console will be :x is now 20, x is now 19 and so on till "x is now 11" after that i value will become more then x mean condition false loop will be terminated.
b) output: x is now 20, after that i value will be mote then x and for loop get terminated.
c) output: x is now 20
x is now 20
x is now 19
x is now 17
x is now 14
x is now 10

please edit your post and place this there.
thank you.

  ·  4 years ago  ·  

Edited, i guess answer are correct now!!