Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

williamrossi
williamrossi
6,232 Points

javascript basics

Create a variable named fullName that combines both the first and last name variables to create a string like "Mary Jones".

var firstName = "will"; var lastName = "jones"; var fullName = (firstName ' ' + lastName); document.write (fullName);

What am I doing wrong? :(

8 Answers

This is the correct answer

var firstName = 'Will';
lastName = 'Jones';
fullName = firstName + lastName;

So you have

var firstName = "will"; 
var lastName = "jones"; 
var fullName = (firstName ' ' + lastName); 
document.write (fullName);

The problem is in the var fullname line. You want:

var fullName = firstName + ' ' + lastName; 

You missed off the first + sign after firstName.

Anik Devaughn
Anik Devaughn
7,751 Points

Random Challenge:

var userInput = prompt("Enter any number"); var convertInputtoInt = parseInt(userInput);

var dicRoll = Math.floor(Math.random() * convertInputtoInt) + 1; alert("you generated this number " + dicRoll);

Code should like this:

var firstName = "will"; var lastName = "jones"; var fullName = ("firstName + lastName")

I'm struggling to find my own errors: https://w.trhou.se/gw6tmbsu5d

Hasha K J
Hasha K J
7,355 Points

var firstName = "Mary"; var lastName = "Jones"; var fullName = firstName + lastName; document.write(fullName);

Yeah I had a problem with that the fix is that the fourth line that has var fullName = ("firstName + lastName"). I would have though you would not have used "" as they are variable not strings. However, we are outputting strings from the variables I think thats the reason.

Sufiyaan Haroon
seal-mask
.a{fill-rule:evenodd;}techdegree
Sufiyaan Haroon
Full Stack JavaScript Techdegree Student 9,558 Points

This is easy and can be answered different ways. You just have to combine the first variable with the last variable using +.

var firstName = "John";
var lastName = "Doe";
var lastName = firstName + lastName;