Consider the JavaScript code below.
var r = [2, 5, 6, 18, 20, 10, 23, 12, 19, 10];
var s = [1, 5, 7, 13, 18, 21, 10, 25, 32, 17, 3];
var x = [0];
var i;
for (i = 0; i <= 9; i++) {
x[i] = r[i];
}
for (i = 0; i <= 10; i++) {
x[i + 10] = s[i];
}
document.write(x[13] + "<br>");
document.write(i);
The values will be displayed on the screen
- (A) 13 and 10.
- (B) 7 and 11.
- (C) 18 and 10.
- (D) 13 and 11.
- (E) 7 and 10.
Answer:
Answer: Letter D
I ran the code and everything OK , the answer is correct, but I was in doubt on the letter A and wrapped in for (i = 0; i <= 10; i++)
. Why are you increasing once more and leaving i=11
instead of i=10
? I ran the same function in java and if I do
for(int i = 0 ; i <= 10 ; contador = ++i) contador=11
for(int i = 0 ; i <= 10 ; contador = i++) contador=10
Does not this last example match the example of the question?