Weblab notebooks are a great way to code interactively. By running small snippets of code you can directly see their effect. Additionally, Weblab let's you add text or illustrations to your source code. Making it easier to understand your code for yourself and others.
Every Weblab notebook is a collection of cells which are either
- code cells or
- markdown cells.
Let's learn more about how to use code and markdown cells.
Code cells are where the "magic" happens. They evaluate your code. To understand how this works, let's look at an example.
The power of programming comes from using abstractions. We have just learned one powerful way of creating abstractions. The declaration of variables. Variables let you refer to certain expressions by names. Variables persist across cell borders and can be reused in other cells. For example:
Another powerful way to create abstractions are functions. A function lets you name a group of operations and then refer to it as a unit. For example:
Are you getting an "undefined" when you run the cell? Don't worry, that's the right value of a function declaration. The function was still defined and is ready to be used. Check it out:
Markdown cells are "text" cells. They let you write comments, add links or add images. Markdown cells have two modes. An edit and a display mode.
As the name suggests, the edit mode enables you to edit the content of the cell. You can get into the edit mode of a markdown cell by double clicking it. The idea behind markdown cells is that you write content in the edit mode according to the Markdown syntax and then display the formatted text by switch into the display mode.
The display mode displays the html that is generated from the markdown source. To switch into the display mode from the edit mode, press "Shift+Enter" or the "Run"-button in the menubar. It's best if you try the whole thing out. Double click on the current cell, edit the content and switch back to the display mode to see the changes.
One very useful feature of markdown is that you can easily create headings. Just prepend a
#before a line and the line becomes a heading. For example:
# Your heading
By using multiple
#you can specify different levels of headings. Using
#gives the highest level heading where as using
######gives the lowest level heading. Have a look at the source of this cell to see that the heading of this cell is a third level heading.
It is also very easy to create lists of items in markdown. You can use
*in front of a line to turn it into a list item. For example:
- apples - bananas - oranges