javascript quiz has , Ended (Answers Part 1)

in javascriptquiz •  4 years ago 

Here are the answers to the quiz for Question No 1 :


images_20201026233222690.jpg

( Question 1 )

1.) window.alert(window.alert("hello"));
here the output will be a alert box with a message saying hello.
After closing that alert box you will get another alert message as undefined.

The reason why second alert message is showing undefined is because it is taking the parameter as window.alert("hello") that is simply undefined.

2.) window.alert( );
Here the output will be a blank alert box. Because here noting is defined inside the brackets. if we would have used a undefined value it must have shown undefined alert box.

3.) window.alert(console.log("@double-u has more 2700000 "));
Again here the same logic is followed just like in first part the alert box with undefined message and in the console we can see a message as :
"@double-u has more than 2700000 BP.

4.) var x = 1;
console.log("window.alert( x++ )");
Here the output will be shown in console box after pressing the F12 as window.alert(x++).

5.) console.log(@afrog is attending the quiz);
Here the webpage will run successfully but when you will press F12 you will see that a error is shown there.
This error is syntax error as none of the variables inside is defined.
(Don't think that the parameter here will be considered as string , they all are acting as variable that are simply not defined)

6.)

        var x = 20 ;
        for(i=0; i<x ; i++)
        { 
          console.log("x is now " + x ); 
        }

Here the output will be , "x is now 20" for 20 times as for loop will be running for 20 times.

7.)
a) x-- ;
we will see in the console that the following pattern of messages is observed.
x is now 20
x is now 19
x is now 18
x is now 17
x is now 16
x is now 15
x is now 14
x is now 13
x is now 12
x is now 11

The reason why there is no further message in console is because now value of x is 11 and value of x is now not more than i so the for loop exits.

b) x=x-20;
here only one output as after that x becomes zero and i becomes 1 and hence loop gets terminated.
x is now 20.

c) x=x-i;
Output will be
x is now 20
x is now 20
x is now 19
x is now 17
x is now 14
x is now 10

You can check the values of i and x and see you will get the above pattern.

d) x= x++ + --x;
here we will see a flood of messages and it will continue till infinity and you will observe that your web page is stucked.
try running this code yourself.

Thank You , i will post answers for Question 2 soon.
stay tuned

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:  

Congratulations! This post has been upvoted by the @blurtcurator communal account,
You can request a vote every 12 hours from the #getupvote channel in the official Blurt Discord.Don't wait to join ,lots of good stuff happening there.