Copy of U8L2 Submit.pdf - You be the AP Reader \u200bYou are the AP reader trying to determine if they get the point for Rows 4 and 5 Assume each function

# Copy of U8L2 Submit.pdf - You be the AP Reader u200bYou...

• 5
• 33% (3) 1 out of 3 people found this document helpful

This preview shows page 1 - 3 out of 5 pages.

You be the AP Reader! You are the AP reader trying to determine if they get the point for Rows 4 and 5. Assume each function below was submitted. For each, select whether Rows 4 and 5 should be awarded and why. No need for detailed explanations, arrows to the code or short bullets are fine. 1 Example Algorithm 1 function repeatWord(word, times){ var returnWord = ""; for(var i = 0; i < times; i++){ returnWord = returnWord + word; } return returnWord; } Earn Row 4? Yes / No Earn Row 5? Yes / No Why? Example Algorithm 2 function increaseScore(points){ score = score + 1; if(score > 10){ endGame(); } } Earn Row 4? Yes / No Earn Row 5? Yes / No Why? Example Algorithm 3 function addList(list){ var total = 0; for(var i = 0; i < list.length; i++){ total = total + list[i]; } return total; } Earn Row 4? Yes / No Earn Row 5? Yes / No Why? Example Algorithm 4 function addPositives(list){ var total = 0; var currentItem; for(var i = 0; i < list.length; i++){ currentItem = list[i]; if(currentItem > 0){ total = total + list[i]; } } return total; } Earn Row 4? Yes / No Earn Row 5? Yes / No Why?
Function Requirements Activity 2 - Two Function Calls (10 mins) 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 2 // 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: