When we write a computer program, we're giving the computer a set of instructions for what we want it to do. Just like we can tell a dog to "sit" or "beg", we can tell a computer to "add" or "print". A computer isn't as furry as a dog, but fortunately, it's a lot more reliable! And just a bit better at math...
Let's start with a simple "Hello World" program, the first program of many new programmers. Our goal is to get the computer to display "Hello World" somewhere on the screen.
That's as simple as:
Try typing that in the editor below:
If you make any typos or syntax mistakes along the way, our error buddy will pop up and let you know. Everyone makes mistakes while programming, so it's totally okay. That's how we learn and improve!
How does it work?
Now let's break down our 1-line program:
That line of code is called a statement. All programs are made up of statements, and each statement is an instruction to the computer about something we need it to do.
println()command is also called a function, method, or procedure. That line tells the computer to call the procedure named
printlnthat knows how to display output in a console.
println()procedure expects a single parameter which specifies what text the computer should display. In this program, the value passed in is "Hello, World!", so that is what's displayed.
Display commands are different in each environment and language. The
alert(), and you'll find even more ways in other languages like Python, Java, and Snap.
Want to join the conversation?
- What's the difference between println and print()?(16 votes)
- It depends on the language and the environment.
println()function in ProcessingJS that prints out to the console, so that's what our examples use. That stands for "print line", as it always puts a new line after whatever it prints.
Other environments may have functions named
print()that print to a console. For example, Python 3 has a
print()function that works similarly to the
- Why do we use println and not text? Is it because there are multiple parameters to text?(7 votes)
- From the author:The text() command displays text on the canvas, while println() displays text in a console. We aren't teaching any ProcessingJS drawing functions in this course, since the focus is on programming concepts common across many languages and environments. Thus, I decided to use println() for the examples.(15 votes)
However, you can use browser provided functions like confirm in our Webpage-making environment here:
Just put it inside a script tag and you'll see the confirmation box pop-up.(9 votes)
- Why do you have to put all those parenthesis and colons and stuff? Why can't you just put: Say "flamingo" Or something like that?(3 votes)
- I learned PHP but it's never taught. Is PHP just too old and irrelevant nowadays?(5 votes)
- Why is it necessary for quotation marks within the parenthesis?(5 votes)
- Yes. If you put there text not in quotation marks JS will thing that this is not a text, but variable, function or other things. For outputting exactly what you've written there you must out text in q.marks, so JS will know that this text is String object.(3 votes)
- For the command 'println',
1. I assume 'print' part refers to required or desired output or IS IT SOMETHING ELSE ?
2. What does 'ln' refer to ?
3. Why are round brackets and then double inverted commas used ?
4. In this particular language, is semicolon analogous to a full stop ?(3 votes)
- 1. "print" refers to the fact that the text is being printed to the standard output.
2. "ln" is an abbreviation for "line"
3. The parentheses are used when invoking a function (such as "println") to group together any arguments used by said function. Referring to "println" again, the function accepts only one argument, a string that will be printed to the standard output. The quotation marks are used to denote the beginning and end of a string.
- will the outcome change if you put 'print' or 'printIn'(3 votes)
printlnwill print a new line to Khan Academy's console.(4 votes)
- how do you say "hello, world" in python(1 vote)