struensee
struensee

Reputation: 606

How am I not using semicolons properly (javascript)?

I'm taking Udacity's intro to JS course and I'm baffled by this tutorial on semicolons!

Here is the question:

Directions: Define two variables called thingOne and thingTwo and assign them values. Print the values of both variables in one console.log statement using concatenation. For example,

red blue

where "red" is the value of thingOne and "blue" is the value of thingTwo. Don't forget to use semicolons!

I've tried pretty much every variation and I keep getting the answer wrong. I receive this message:

What Went Well

  • Your code should have a variable thingOne

  • Your code should have a variable thingTwo

  • Your code should only have one console.log statement

  • Your code should print out the values of thingOne and thingTwo using concatenation

What Went Wrong

  • Your code is missing semicolons at the end of each line

Here is my answer:

var thingOne = "red";
var thingTwo = " blue";
console.log(thingOne + thingTwo);

I've also tried:

var thingOne = "red"; var thingTwo = " blue";
console.log(thingOne + thingTwo);

I've also tried both combinations of these wherein the console.log statement does NOT have a semicolon at the end...just to see if that was the problem.

None of these is passing the test.

Is this their error or am I missing something? Sorry for the absurdly simple question. I just want to make sure I'm learning JS properly. Thanks

Upvotes: 0

Views: 372

Answers (3)

SpaYco
SpaYco

Reputation: 1

var thingOne = "red";//" "==> space
var thingTwo = " blue";//" "==> space
console.log(thingOne + thingTwo);//" "==> space

you have space after the line's semicolon, and they need ";" at the end. just a bug

EDIT : for some reason I'm getting downvotes even though that's what happened, it happened to me and i removed the spaces after each semicolon and it got passed.

Upvotes: -2

Zobia Kanwal
Zobia Kanwal

Reputation: 4733

You can simply run and check your code on browser developer console like this: enter image description here

And yes both of your codes are working perfectly fine.

Keyboard shortcuts to open developer console on chrome are as follows:

On Windows and Linux: Ctrl + Shift + J.

On Mac: Cmd + Option + J.

Upvotes: 1

JohnnyAwesome
JohnnyAwesome

Reputation: 518

Your solution is this:

var thingOne = "red";
var thingTwo = "blue";
console.log (thingOne + " " + thingTwo);

https://repl.it/@meghann/Programming-Quiz-Semicolons-2-8

Upvotes: 2

Related Questions