4.9 Calculate Space Mission Exercise

I have complete the assignment for exercise 4.9, calculate the space mission to Mars and the Moon. I can not figure out how to put whitespace between strings and variables. When I run my code for console.log(shuttleName + “will take” + daystoMars + “days to reach Mars.”), shuttlename and will, and
take and daystoMars, are right next to each other, no space. I have tried a comm and , neither works, also tried &nbsp.

JS doesn’t execute whitespace. Your way around it is to log it as a character of a string. From this point you can then append it to the string preceding/succeeding during concatenation.


let adjective = “amazing”;
console.log(“The world is an " + adjective + " place to live in.”);
// Prints: The world is an amazing place to live in.

In order for both of my spaces to register I had to append those to the string portions of my code as fully fledged characters. Try it & ping me back if it doesn’t work out!

1 Like

Hi Tanishab30, I just did it this way:
… + " will take " + daystoMars + " days to reach Mars.").

I put a space after the first quotation mark and a space before the end of the end of the quotation mark.

1 Like