Using Variables

Printing Variables within Sentences

cheese-1129908_960_720Printing just a variable value like Pikachu or Squirtle isn’t very helpful. Add sentences and cheesevariable string values together using a plus (this is called concatenation):

newbs23

This will print:

newbs25

Remember to use speech marks for your printed statements but print the variable name to display the variable value:

newbs24

This would print:

newbs26

Printing Number Variables within Sentences

cookieIf you want to match together strings and number values then it is easiest to use a comma as a plus will not work:

 

This will output:

screenshot-repl-it-2016-11-05-21-04-39

newbs28

Variables not working? Tick off these common errors:

Consistent variable name?
Variable name only one word?
Don't use speech marks to print the variable
Does the variable have a value
Have you used a comma between different sections?

< Back to Section One