Puzzles are fun. Some people like crossword puzzles and some people like Sudoku. Solving a puzzle is rewarding, it gives you a sense of accomplishment. I like coding puzzles. They provide a logical challenge to solve a problem and learn a bit of coding.
I’m writing coding puzzles to provide you a gentle introduction to coding using a variety of coding languages. After each puzzle, I’ll give you the opportunity to solve the puzzle and then share the answer with you. I’ll also explain how the code works.
I’m writing coding puzzles to provide you a gentle introduction to coding using a variety of coding languages. After each puzzle, I’ll give you the opportunity to solve the puzzle and then share the answer with you. I’ll also explain how the code works.
What does this code do?
- Print the message "Hello world!" and then What is your name?"
- Print the message "Hello world!", ask "What is your name?", and then print the name you entered.
How the code works
This example uses a beginner's language called Blocks that you can access free of charge on the Trinket website. The code does the following:
This example uses a beginner's language called Blocks that you can access free of charge on the Trinket website. The code does the following:
- print "Hello world" prints the message Hello world!
- yourName is a variable. Variables hold values.
- prompt for text with message, "What is your name?" This asks you What is your name? The name you type in is stored in the variable yourName by the set yourName command.
- print yourName prints the name you typed in.
Here is the output after running the program. I typed in the name Alan.