Another Contest to win a copy of Ajax In Action
Over on DynamicDrive.com, they are holding a contest where you can win a copy of Ajax In Action. See the website for details!
Eric Pascarello
Moderator of HTML/JavaScript at www.JavaRanch.com
JavaScript: My Personal JavaScript Short Interview Quiz
I was asked by a person about what would you like to see asked on an interview where we should assume the person has a working knowledge of JavaScript. It had me thinking a bit and here are the questions I would ask on an interview. I tried to attack areas that people with a good working knowledge of JavaScript would be able to answer in a very short period of time.
The Quiz
Question 1:
Without running the following code, please tell me what the alert messages would return when executed.
<script type="text/javascript">
var a = "123";
b = 123;
function test(){
b = parseInt(a);
a += 1;
c = "eric";
var d = "pascarello";
}
alert(typeof(a));
alert(typeof(b));
alert(typeof(c));
alert(typeof(d));
test();
alert(typeof(a));
alert(typeof(b));
alert(typeof(c));
alert(typeof(d));
</script>
Question 2:
Write a function that takes a string as an input and returns an array containing the odd words. With the string: "I can sing bad songs while in the shower", the output in the alert should read: "I sing songs in shower". Below is the basic framework that you should use.
<script type="text/javascript">
var strTest = "I can sing bad songs while in the shower";
function obtainOddWords(strPassed){
//Place your code here!
return arrOddWords;
}
alert(obtainOddWords(strTest));
</script>
Question 3:
Take the function in question 2 and create a String prototype so I can call the method using the following statement:
alert(strTest.obtainOddWords())
My Comments on the Questions
Now as you can see the questions are not asking DOM methids or anything like that. If I could ask more questions I would attack those, but I am looking for a certain things in these three questions. This is what the questions would tell me about your knowledge.Question 1 is looking at your knowledge of JavaScript's local and global nature when declaring variables. There is a few tricks in it. A person that has only started with JavaScript may not see them.
Question 2 is not too difficult, the real reason I would ask this is to see how your brain works. There are multiple ways to attack it so there are multiple solutions. Some solutions are a lot better than others.
Question 3 is rather simple if you know what a prototype is. I would not expect that everyone that takes this quiz would be able to answer #3.
Grading:
If you want your quiz to be looked over by me, send a plain text file (.txt) with the answers to JRblog@pascarello.com. Please do not send any other type of file or I will not read it. Do not post answers in the comments, I want to give everyone a fair chance at the answers!Eric Pascarello