[KEY] Create PT - Survival Guide 20_21.pdf - KEY Create PT...

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

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 KEY Create PT Survival Guide 2020 - 2021 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 Yes a parameter is included that is used inside the function Earn Row 5? Yes / No No, the function does not include an if-statement (selection) Why? Example Algorithm 2 function increaseScore(points){ score = score + 1; if(score > 10){ endGame(); } } Earn Row 4? Yes / No No, the parameter is never used in the function Earn Row 5? Yes / No No, the function does not include a loop 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 Yes, the parameter is used inside the function Earn Row 5? Yes / No No, once again an if-statement is not included inside the function (selection) 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 Yes, the parameter is used inside the function Earn Row 5? Yes / No Yes, the function includes examples of sequencing, selection (an if-statement), and iteration (a loop) 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.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture