Well done!
You have completed Hello Full Stack JavaScript !
You have completed Hello Full Stack JavaScript !
Now that you've practiced storing values in variables, it's time to learn more about how variables can be used in programs. Here we will practice operations on different types of data. With numbers, we can use the plus sign for addition but when using the string data type we've learned about, the plus sign combines strings into one larger string .
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upNow that we've tried storing values in variables, 0:00 let's practice using variables in ways we might while programming with JavaScript. 0:03 Earlier I mentioned that the number type in JavaScript allows you to perform 0:07 mathematical operations. 0:11 Based on what you learned in the last video, try creating two variables and 0:13 assign each a different number value. 0:18 Once created, use the variable names to add the variables together, and 0:21 then print this outcome to the console. 0:25 Pause here and give it a try. 0:29 If you weren't able to figure it out, don't worry, we'll try it together. 0:33 Before we write any new code, let's use the clear command to clean up the console. 0:38 That's the word clear followed by parentheses. 0:43 First, let's create a variable named number1 and set it equal to 100. 0:48 Now, we'll set a variable name number2 to 150. 0:59 Next, we'll combine them using the plus sign or 1:12 addition operator by typing number1 + number2. 1:16 Now when you press Enter, you'll see the result of this equation. 1:23 You can even see a preview before. 1:28 Nice work. 1:31 What do you think might happen if we try adding two strings together? 1:32 Try typing "hello" + "fsjs" and press Enter. 1:36 We get a combination of the strings without any spaces. 1:49 Other data types aren't allowed to do math, but 1:53 they come with their own operations. 1:55 For instance, when it comes to strings, the plus sign is referred to as 1:58 a concatenation operator and is used to combine two or more string values. 2:02 Let's try combining variables that store our first and 2:08 last names to print our full names. 2:11 We'll clear the console again, and I will create a variable named firstName, 2:12 Make sure it's a string, And a variable named lastName, 2:23 And combine those variables. 2:38 And uh-oh, again, we get our names together without a space between. 2:45 Concatenation works with exactly what we give it. 2:51 Let's add a space between the two names by using one more concatenation operator and 2:54 wrapping a space in quotation marks. 3:00 There we go, well done. 3:13 I've added a link to resources on concatenation and 3:16 strings to the teacher's notes. 3:19 I'll always encourage you to check the teacher's notes for helpful links that can 3:21 further your understanding of the concept we're learning. 3:25 You've gotten a glimpse of the power JavaScript gives developers to take input, 3:28 compute data, and provide output. 3:33 We've only scratched the surface. 3:36 Speaking of a surface, in the next video, 3:38 we'll have some fun making changes to the presentation layer of a web page with 3:41 JavaScript, just like a front-end developer does on the job. 3:45
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up