< Language Tutorials

SandCastleIcon.png This article has links to websites or programs outside of Scratch and Wikipedia. Remember to stay safe while using the internet, as we cannot guarantee the safety of other websites.

This tutorial will teach how to make an Elm program that shows "Hello World!" on the screen. The Elm playground can be used for this tutorial. Press the "Compile" button at the top to run the Elm code.

Scratch Code

In Scratch, this is the easiest way to show a line of text somewhere on the screen:

when flag clicked
say [Hello World!]

Elm Code

Elm shows things on the screen by generating HTML elements. You must start by importing the Html module, which is similar to adding the Pen or Music extensions in Scratch.

import Html

Next, an element that shows the text is needed. Use the text function from the Html module:

Html.text "Hello World!"

Finally, it is needed to define a variable called main which specifies the program's behavior and how it responds to events.

When using an HTML element as the value for main, Elm will automatically turn it into a program that just shows the element.

main =
    Html.text "Hello World!"

The final result:

import Html

main =
    Html.text "Hello World!"

Cookies help us deliver our services. By using our services, you agree to our use of cookies.