Tell text from numbers — quick review
A locker door has two printed tiles on it, a 7 and then a 2, and the label reads seventy-two.
Use addition for two integers and joining for two strings. Check for quote marks before deciding which operation this example uses.
Find the
+and the value on each side of it. In this lesson both values always have the same type.Look at the edges of each value for a pair of matching quote marks.
If both values have quotes, they are strings: write the characters of the left value, then the characters of the right value.
If neither value has quotes, they are integers: add them as you would on paper.
Write what
printshows: the result with no quote marks, on a line of its own.
A natural mistake is to assume that anything made of digits will add. You see a 7 and a 2 in both 7 + 2 and "7" + "2", so it feels natural to expect 9 from both. The quote marks change the type: inside them each digit is a character tile, and + sets the tiles side by side to make 72. Before you predict a +, look at the edges of each value, not at the digits.