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 JavaScript Basics (Retired) Storing and Tracking Information with Variables The Variable Challenge Solution

Multiple strings inside one single variable = not working

Hello,

1) Why this is not proper JavaScript code? I'm getting "Uncaught SyntaxError: Unexpected string" error in Chrome.

var adj_tyhma = prompt('Kirjoita adjektiivi vastaavassa muodossa kuin PINNALLISUUDESTAAN tai HAUSKUUDESTAAN.');
var sub_juustopala = prompt('Kirjoita substantiivi vastaavassa muodossa kuin OMENAN tai LEIJONAN.');
var ver_lentaa = prompt('Kirjoita verbi vastaavassa muodossa kuin LAULELI tai KULJESKELI.');

var ensimmainen_kpl = 'Olipa kerran korppi, joka oli kuuluisa ' + adj_tyhma '. Eräänä päivänä se löysi ison ' + sub_juustopala '. Se ' + ver_lentaa ' ympäriinsä ja esitteli ' + sub_juustopala 'aan ylpeänä metsän väelle.';

document.write(ensimmainen_kpl);

2) Can I use scandinavian letters äöå when naming variables?

1 Answer

Justin Iezzi
Justin Iezzi
18,199 Points

For 1, it looks like you're not combining your variables with the strings correctly. You're missing the trailing + required after each variable.

This should work -

var ensimmainen_kpl = 'Olipa kerran korppi, joka oli kuuluisa ' + adj_tyhma + '. Eräänä päivänä se löysi ison ' + sub_juustopala + '. Se ' + ver_lentaa + ' ympäriinsä ja esitteli ' + sub_juustopala + 'aan ylpeänä metsän väelle.';

For 2, yes I believe you can. But I might recommend against it if possible. Here's a good discussion on the topic.

Of course I was missing + ! Thanks a lot :)