0

I'm a little lost on these questions of a quiz I just took...Any help is appreciated!

1st question:

What is the value of returnValue in the following code segment?
returnValue = 17 = = "17";

answer choices:
True
False
17
NaN

*I chose True<--I think that's right, but I'm not sure how I would write it in javascript. Could someone please help me with that?

2nd Q:

What is the value of y after the following statements execute?
var y = 6;
var x = 8;
y = y * x / y;
y = 25 % 5;

answer choices:
0
6
8
48

*I chose 0<--Could someone show me how to write that one in javascript and have a return answer.

3rd Q:

The _____ is especially useful for working with arrays.

answer choices:
while
do…while
for
switch

*I chose while???<--The answer is for so I got it wrong. Can someone explain this to me as I can't find the reason why in my book.


Thanks for any help.

Jake

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Taywin
0

#1, the answer is 'true' because JavaScript evaluates an integer string and an integer as equal in this case (17=="17")

#2, the answer is 0 because the last assignment of y is 25 % 5 (25 mod 5).

#3, should be for-loop as the answer because you knows the length of the array. For-loop is good to use when you are iterating a known length collection (shouldn't introduce array of out bound). However, it would be inappropriate to use for-loop if you are dealing with dynamic array size (in this case, while-loop is more appropriate). While-loop or do-while is OK with an array; however, you will need to manually increment the variable you used in the loop yourself --> dangerous if forgot to do it. Besides, there would be a chance to get an error if use do-while (when array is empty). Switch is out of question because you could introduce an error (array out of bound).

<script type="text/javascript">
// #1
alert(17=="17")

// #2
alert(25 % 5)
</script>

Edited by Taywin: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.