Search This Blog

Tuesday, July 20, 2010

Javascripting QnA

Please note that the source of these questions is w3schools and answers are to the best of my knowledge.

Q1: Inside which HTML element do we put the JavaScript?
A1: "script" element

Q2: What is the correct JavaScript syntax to write "Hello World"?
A2: document.write("Hello World!");

Q3: Where is the correct place to insert a JavaScript?
A3: Both the "head" section and the "body" section are correct

Q4: What is the correct syntax for referring to an external script called "xxx.js"?
A4: script src="xxx.js"

Q5: An external JavaScript must contain the script tag
A5: False

Q6: How do you write "Hello World" in an alert box?
A6: alert("Hello World");
Note1: Confirm Box syntex is confirm("sometext");
Note2: Prompt Box syntex is prompt("sometext","defaultvalue");

Q7: How do you create a function?
A7: function myFunction()
Note: Syntex is function functionname(var1,var2,...,varX){some code}

Q8: How do you call a function named "myFunction"?A8: myFunction()
Q9: How do you write a conditional statement for executing some code if "i" is equal to 5?A9: if (i==5)

Q10: How do you write a conditional statement for executing some code if "i" is NOT equal to 5?A10: if (i != 5) // I think. Please check

Q11: How does a "while" loop start?
A11: while (i<=10)
Note: It has variant
do
{ code to be executed }
while (var<=endvalue);

Q12: How does a "for" loop start?
A12: for (i=0; i<=5)

Q13: How can you add a comment in a JavaScript?
A13: //This is a comment

Q14: What is the correct JavaScript syntax to insert a comment that has more than one line?A14: /*This comment hasmore than one line*/

Q15: What is the correct way to write a JavaScript array?
A15: var txt = new Array("tim","kim","jim")

Q16: How do you round the number 7.25, to the nearest integer?
A16: Math.round(7.25)
Note1: Other important Math Objects are:
  • random()
  • max()
  • min()
  • floor()
  • ceil()
  • abs()

Note2: JavaScript provides eight mathematical constants that can be accessed from the Math object. These are: E, PI, square root of 2, square root of 1/2, natural log of 2, natural log of 10, base-2 log of E, and base-10 log of E.

Q17: How do you find the number with the highest value of x and y?
A17: Math.max(x,y)

Q18: What is the correct JavaScript syntax for opening a new window called "w2" ?
A18: w2=window.open("http://www.w3schools.com");

Q19: How do you put a message in the browser's status bar?
A19: window.status = "put your message here"

Q20: How can you find a client's browser name?
A20: navigator.appName
Note1: The navigator object contains information about the browser.
Note2: Some properties of this object are appCodeName, appName, appVersion, cookieEnabled, platform, userAgent.
Note3: Some methods of this object are javaEnabled(), taintEnabled()

No comments:

Post a Comment