Question: Response 3d asks you to describe two different calls to the same function with different arguments that cause the function to run differently. For this
Response 3d asks you to describe two different calls to the same function with different arguments that cause the function to run differently. For this activity you should:
- Write out two different calls to the function listed on the left with different arguments. For example
- findMax([2,3,4]) and findMax([10,20,30])
- Describe the specific line of code that will run differently based on the different inputs
- List what the output of each function call will be
// This function finds the maximum value in
// a list and returns it.
01 function findMax(list){
02 var max = list[0];
03 for(var i = 0; i < list.length; i++){
04 if(list[i] > max){
05 max = list[i];
06 }
07 }
08 return max;
09 }
Call 1:
Call 2:
Which condition runs differently:
Result of Call 1:
Result of Call 2:
// This function checks if the game is over
// If the score is more than 100 then it hides
// all the enemies and runs the endGame function
// that shows your final score.
01 function checkEndGame(score){
02 if(score > 100){
03 for(var i = 0; i < 3; i++){
04 setProperty("enemy"+i,"hidden",true);
05 }
06 endGame();
07 }
08 }
Call 1:
Call 2:
Which condition runs differently:
Result of Call 1:
Result of Call 2:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
