The code is received in its programmer-friendly text form and processed directly from that. Here we are selecting a text paragraph , then attaching an event listener to it so that when the paragraph is clicked, the updateName() code block (lines 5–8) is run. The updateName() code block (these types of reusable code blocks are called “functions”) asks the user for a new name, and then inserts that name into the paragraph to update the display. Everything is as you expect, and how it works in most programming languages.
Create a variable called carName and assign the value Volvo to it. This tutorial supplements all explanations with clarifying “Try it Yourself” examples. We recommend reading this tutorial, in the sequence listed in the menu.
If you pass a number, that always evaluates to true unless it’s 0. If you pass a string, it always evaluates to true unless it’s an empty string. After assignment and math operators, the third set of operators I want to introduce is conditional operators.
- You’ve seen this stuff already in the course, but only in passing — here we’ll discuss it all explicitly.
- You should try and practice writing code every day if you can, or at least as often as possible.