C3.2 Read and alter existing code, including code that involves events influenced by a defined count and/or subprogram and other control structures, and describe how changes to the code affect the outcomes and the efficiency of the code.

Activity 1: Percentages


Provide the student with code that contains a subprogram like this:

Blocks of codeEvents block stating, “when green flag is clicked.”Variable blocks stating, “set sum to 0”. Variable blocks stating, “set total, open parenthesis with «H», «S», «T», closed parenthesis, to 0.”List block stating, “delete all of purchased items.”Control block stating, “repeat until answer equals N.”Inside 4 nested blocks.Sensing block stating, “ask what is the cost of the item, question mark, and wait.”List block stating, “add motions block “answer” to purchased items”.Variables block stating, “change sum by’’ sensing block stating, ‘’answer’’.Sensing block stating, “ask do you have another item to add, question mark, open parenthesis, y or n, closed parenthesis and wait. Variables block stating, “if sum multiplied greater than 100 then’’. Inside one nested block.My block stating, “30 percentage rebate”.Control block stating, “else”.Inside one nested block.Variables block stating, “set total open parenthesis, with «H», «S», «T», closed parenthesis, to sum multiplied by one decimal 13.
Block of codes:My block stating, “define 30 percentage rebate.”List stating, “set amount saved to sum multiplied by zero decimal 3.”List stating, “total, open parenthesis, rebate, closed parenthesis, to sum minus amount saved.”List stating, “set total, open parenthesis with «H», «S», «T», closed parenthesis, to total, open parenthesis, rebate, closed parenthesis, multiplied one decimal 13.”

Ask students to add subprograms that they think are relevant to how the code works. For example:

  • add subprograms for 10% and 20% discounts under appropriate conditions;
  • add a subprogram to allow for HST exemption when a condition is met;
  • use the block (items in the list) to offer a discount if the order exceeds a certain number of items.

Activity 2: Altering a Code


Provide the code below to the student:

Blocks of codeEvents block stating, “when green flag is clicked.”Variables block stating, “set sum to 0”. Variables block stating, “set total, open parenthesis with «H», «S», «T», closed parenthesis, to 0.”List block stating, “delete all of purchased items.”Control block stating, “repeat until answer equals N.”Inside 4 nested blocks. Sensing block stating, “ask what is the cost of the item, question mark, and wait.”Lists block stating, “add motions block “answer” to purchased items”.Variables block stating, “change sum by’’ sensing block stating, ‘’answer’’.Sensing block stating, “ask do you have another item to add, question mark, open parenthesis, y or n, closed parenthesis and wait. Variables block stating, “if sum greater then 100 then. Inside one nested block.My block stating, “30 percentage rebate”.Control block stating, “else”.Inside one nested block.Variables block stating, “set total open parenthesis, with «H», «S», «T», closed parenthesis, to sum multiplied by one decimal 13.
Block of codes:My blocks stating, “define 30 percentage rebate.”List stating, “set amount saved to sum multiplied by zero decimal 3.”List stating, “total, open parenthesis, rebate, closed parenthesis, to sum minus amount saved.”List stating, “set total, open parenthesis with «H», «S», «T», closed parenthesis, to total, open parenthesis, rebate, closed parenthesis, multiplied one decimal 13.”

Ask the student to predict what would happen if the "change SUM by answer" block was removed.

Ask questions such as:

  • Would the code remain functional?
  • Would the code give the desired outcome?
  • How could you restore the code without using this same block to calculate the sum of the items purchased?