Please use this identifier to cite or link to this item:
Show full item record
https://sei.ubc.ca/handle/seima/1762
Item Type: | Concept/Clicker Questions |
Subject(s): | Connecting with Computer Science |
Title: | JavaScript - Set 1 |
Description: | First set of concept questions. The "boilerplate code" question is designed to be given BEFORE any substantial discussion of how function calls work. Students should give their best guess of what it displays. The point is that, even never having really worked with code before, many students can correctly predict the outcome. It's to build their confidence so that they'll TRY to predict in the future. Make clear that, even where predictions go wrong, that's a learning opportunity! And, be sure to discuss how students came about "wrong" answers and how these answers are important (because they show how intelligent humans will interpret the code, which helps us learn more about programming and process descriptions and also is valuable data for when we design our own languages to express process!). Note: for some reason PRS refuses to export these questions as PDF :(. The questions simply trace values through the following code. One additional question asks what order the code is executed in (trying to get at the idea that: first the function is declared (the computer "learns" a new command called tryMe), then the alert is executed, which sends us back into executing the code for tryMe). function tryMe(num1, num2) { var x, y, z; alert("The value in x after 'var x, y, z;' is: " + x); x = num1; alert("The value in x after 'x = num1;' is: " + x); alert("The value in num1 after 'x = num1;' is: " + num1); y = num2; alert("The value in y after 'y = num2;' is: " + y); alert("The value in num2 after 'y = num2;' is: " + num2); x = y; // y = x; alert("The value in x after 'x = y;' is: " + x); alert("The value in y after 'x = y;' is: " + y); z = x + y; alert("The value in z after 'z = x + y;' is: " + z); z = z + 1; alert("The value in z after 'z = z + 1;' is: " + z); alert("The value in x after 'z = z + 1;' is: " + x); alert("The value in y after 'z = z + 1;' is: " + y); alert("The value in x just before the return statement is: " + x); alert("The value in y just before the return statement is: " + y); alert("The value in z just before the return statement is: " + z); alert("The value in num1 just before the return statement is: " + num1); alert("The value in num2 just before the return statement is: " + num2); return z; } alert( tryMe(3, 4) ); - |
Author(s): | Steve Wolfman |
License: | CC BY-NC 3.0 |
Access to Item: | Open |
Accessibility Features: | unknown |
Accessibility Hazards: | unknown |
Appears in Collections: | UBC-CPSC 101: Connecting with Computer Science |
Files in This Item:
File | Description | Size | Format | |
---|---|---|---|---|
boilerplate.html | 24.77 kB | HTML | View/Open | |
class-6-js.xml | 24.77 kB | XML | View/Open |
This item is licensed under Creative Commons License