<script language="JavaScript">
var a = [1,2,3,4,5,6,7,8,9,10];
var display = whatisthis(a, a.length);
document.writeln("<h1>Output:" + display + "</h1>");
function whatisthis(b, chkdis) {
if (chkdis == 1)
return b[0];
else
return b[chkdis - 1] + whatisthis(b, chkdis - 1);
}
</script>
2nd question. What is the value of the variables b and d after the following JavaScript code is executed?
<script type="text/javascript">
var a = 5, b = 2, c = 2, d = 1;
var fruit = new Array();
fruit[0] = "pear";
fruit[1] = "apple";
fruit[2] = "guava";
fruit[3] = "orange";
fruit[4] = "grape";
fruit[5] = "avocado";
fruit[6] = "cherry";
if( b <= c ){
d = a – b * c;
b = fruit[d];
} else {
d = a;
b = fruit[c];
}
alert( "b now contains: " + b + " and d contains: " + d);
</script>
Can anyone explain to me what are the answers of those two questions and how you came to it?
Javascript array question
in JavaScript
Posted
1st question.
2nd question.
What is the value of the variables b and d after the following
JavaScript code is executed?
Can anyone explain to me what are the answers of those two questions and how you came to it?