This course has been updated! We now recommend you take the Complete Intro to Web Development, v2 course.

Check out a free preview of the full Introduction to Web Development course:
The "Exercise 5: Writing JavaScript" Lesson is part of the full, Introduction to Web Development course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, you will write your first JavaScript program. It’s a simple program that declares a variable and pops up a message with that variables value.

Get Unlimited Access Now

Transcript from the "Exercise 5: Writing JavaScript" Lesson

>> [MUSIC]

>> Nina Zakharenko: Let's write our first JavaScript. We're going to use one of those annoying popups, and we're gonna create a variable which is our names, and then we're gonna popup a message. So let's open this codepen here.
>> Nina Zakharenko: So, here's my stuff.
>> Nina Zakharenko: Set a variable to myName and popped up an alert.

[00:00:32] You can go ahead and comment that out if you want to keep it at the top for a reference.
>> Nina Zakharenko: So I'll give you guys a few minutes to do this exercise. So add a second string, have it be a variable name. Add a third variable called age, set it to your age and then create an alert that will popup your name and your age.

>> Brian Holt: They're asking, how to you bring the console up in CodePen?
>> Nina Zakharenko: Same, you would go to View > Developer > JavaScript Console.
>> Nina Zakharenko: But if you output your results using an alert you won't need to look in the console.
>> Speaker 3: As part of the browser, not part of the web page.

>> Nina Zakharenko: What's that?
>> Speaker 3: The console is part of the browser-
>> Nina Zakharenko: Yes.
>> Speaker 3: Not part of the webpage.
>> Nina Zakharenko: Exactly.
>> Nina Zakharenko: Thank you CodePen, for being helpful.
>> Nina Zakharenko: So you can use either a single or double quote but to stay consistent, I'm going to use double quotes.
>> Nina Zakharenko: Doesn't matter which one you pick as long as you pick one and stick with it.

>> Speaker 4: Are numbers just numbers, are they integers or floats or?
>> Nina Zakharenko: Depends.
>> Speaker 4: Okay, so it does have that capability of distinguishing.
>> Brian Holt: No, it doesn't.
>> Speaker 4: It doesen't?
>> Nina Zakharenko: No.
>> Brian Holt: Everything is a number in JavaScript which is a float. So doing math in JavaScript sucks.
>> Nina Zakharenko: Yes, don't use JavaScript for math.

[00:02:47] But you can declare it for a kind of- There are libraries that can help, we need to do like more precisely.
>> Brian Holt: Yeah, everything's a float.
>> Nina Zakharenko: So.
>> Nina Zakharenko: Okay, let's do this exercise. So, I'm gonna use Brian's name.
>> Nina Zakharenko: I'm gonna say, he's about 105.
>> Speaker 3: [INAUDIBLE]

>> Nina Zakharenko: Don't forget your semi-colons like I did.
>> Nina Zakharenko: Okay, so, we're going to use an alert and we're gonna say name and use a plus sign to put together strings. And were gonna type is in here.
>> Nina Zakharenko: Brian's 105 years old.