Room for Growth explainer


#1

The aim of this puzzle: Use the addition assignment += operator to add to a variable’s value.

Walkthrough of the solution: When updating the value of a variable, a new value must be assigned to the variable. The usual way to do this would be something like:

let x = 5;
x = x + 2;

This tells the code, “Take the current value of x (which is 5), add 2, and reassign it to x.” x would now equal 7.

A shorter way to write this is to use the += operator:

let x = 5;
x += 2;

Is the same as:

let x = 5;
x = x + 2;

To complete this puzzle, use the += operator to add newRoom to squareFeet.

Sample code solution:
(Tap below to reveal)

let squareFeet = 800;
let newRoom = 400;

squareFeet += newRoom;
print('Total square feet is now: ' + squareFeet);

JavaScript Concepts: Addition Assignment Operator, Variable Declarations with Let

Grasshopper Concepts: print()