text
stringlengths
0
897
print "My name is 101001."
print "@*#$!! I spilled bits on my chips!"
print "Later alligator!"
```
You can try out those lines one at a time if you like. Or, you can type them all in at once, with each `print` statement on a new line in the code editor, as shown above. In that case each message will appear in the output area, one after the other.
Notice how the strings can contain any combination of letters, numbers, and punctuation. They can even contain foreign characters or emoji; if you know how to type any of these, go ahead and give it a try. It's all just strings to MiniScript.
There is one exception, however. What if you wanted to put quotation marks inside your string? That's problematic, since the quotation marks are how MiniScript knows where the string ends. If you stick some in the middle, it will think your string is done, and won't know what to do with the rest of it, resulting in ...
The solution is to enter the quotation marks *twice* if they occur within a string.{i: "quotation marks"}
I> To include quotation marks in a string, enter them twice in a row.
Here's an example:
{caption: "Quotation marks within a string"}
```miniscript
print "Hello, ""Bob,"" if that is your real name."
```
Try that. You should see in the output window that the doubled quotation marks have magically transformed into ordinary quotation marks. This is just a trick to work around the problem of MiniScript knowing where your strings end, and it is the only character that is special in this way.
You now know just about everything there is to know about defining a string. Strings are one of the four basic types of data in MiniScript. Before calling it a day, let's learn about one other type: numbers.
{i:"number;data type, number"}
Numbers are easy. They are exactly what you think they are. Here's an example:
{caption: "The ultimate answer"}
```miniscript
print 42
```
Here, `42` is a number. Nothing to it, right? Numbers can be any size, and can include a decimal point or not. They can also be written in *exponential notation*, which is sometimes convenient for very large or very tiny numbers.
exponential notation
: a way of writing numbers like 2.5E10, where the number after the "E" means to shift the decimal point that many places to the right (or to the left, if the number is negative)
So 2.5E6 is 2.5 times a million (i.e., a 1 followed by 6 zeros), or 2.5 million. 2.5E-6 would be 2.5 times a millionth. You won't need this form of numbers very often, but now you know it exists.
W> Many regions of the world write their numbers differently, for example, with a comma instead of a period to separate decimals. MiniScript, like most other computer languages, always uses a period as the decimal point, no matter where you are.
W> Also, you may be used to writing large numbers with some grouping character before the thousands, millions, and so on. That makes it easier for humans to read, but it only confuses computers. So even a big number like 7,603,985,818 (the population of Earth at the time of this writing) must be written 7603985818.
We'll end the chapter with one last little sample program. This prints a variety of strings and numbers. If you've just been reading and nodding at the examples above, you should be sure to type in this one. Typing in code trains your fingers and your brain, and will make learning to code that much easier.
{caption: "Printing strings and numbers"}
```miniscript
print "The answer to the Ultimate Question..."
print "of life, the universe, and everything..."
print "is..."
print 3.14157
print "...wait, no, it's actually:"
print -2.5E6
print "...no, I'm sorry, the answer is:"
print 42
```
D> Were you surprised by how one of those numbers came out? Strings appear exactly as you type them -- except for doubled quotation marks -- but numbers come out in a standardized format, which may be different from how they appear in your code.
And that wraps up day 1! You have taken your first steps down an incredibly rewarding path. Let's review what you learned today:
A> **Chapter Review**
A> - You can run MiniScript code on the web at <https://miniscript.org/>.
A> - You know how to use `print` to display strings and numbers.
A> - You learned that MiniScript is case-sensitive, and how to recognize and correct mistakes in your programs.
{chapterHead: "Day 10: Maps", startingPageNum:105}
{width: "50%"}
![](Chapter10.svg)
Q> Feeling a little uncomfortable with your skills is a sign of learning, and continuous learning is what the tech industry thrives on!
Q>— Vanessa Hurst (founder and CEO, CodeMontage)
A> **Chapter Objectives**
A> - Learn about the *map* data type.
A> - Get or set map values with square brackets or dot syntax.
A> - Iterate over a map with a `for` loop.
A> - Get an overview of intrinsic map functions.
{i:"map;data type, map"}
You've already learned about numbers, strings, and lists. There is one more basic data type in MiniScript: maps. A *map* is like a two-column table, where each unique value on the left column is associated with some other value on the right.
{caption:"An example map: four fictional heroes and their ages", hPad:10, vpad:3}
| key | value |
| --- | ----- |
| Buffy | 17 |
| Willow | 16 |
| Xander | 17 |
| Oz | 18 |
The values in the left column are "mapped" to values on the right. In some languages, this is called a *dictionary*, because you can think of a dictionary as a book that maps each word to a definition (or list of definitions).
{i:"map;dictionary"}
map
: a data type that contains a list of key/value pairs, with each unique key associated with one value