Your first JavaScript program
Use console.log to make a program say something.
- Run JavaScript code
- Print text with console.log
- Recognize strings and statements
JavaScript is the language that makes web pages respond to people. It also runs on servers, desktop apps and phones. Start with one instruction: console.log writes a value to the console.
console.log("Hello, world!");Hello, world!
Text inside quotes is a string. JavaScript executes statements from top to bottom. A semicolon marks the end of a statement; JavaScript can often insert one for you, but writing it makes examples clear.
Key takeaways
JavaScript runs statements in order.
console.log(value)displays a value.Put text in quotes to make a string.
Lesson quiz
5 questions · pass with 4 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Practice: write JavaScript
Write the program, run it against the test cases, and use the feedback to build your JavaScript skills.
Personal greeting
Use the provided input string as a name. Print Hello, NAME!. If the input is empty, use friend.
- Name provided
- Empty input
JavaScript runs in a sandboxed browser frame with a 1.5 second time limit. Input is available as the string variable input.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…