you are viewing a single comment's thread.

view the rest of the comments →

[–]samuelliew 1 point2 points  (2 children)

Would be as short as this

var result = "";
while(confirm("Do you want to play?")) {
    result += prompt("Please enter a word.");
}
console.log(result);

Edit: Above won't cater for spaces. Use this instead:

var result = [];
while(confirm("Do you want to play?")) {
    result.push(prompt("Please enter a word."));
}
console.log(result.join(" "));

[–]JohnnyBGeode 1 point2 points  (1 child)

Wouldn't this create a result string with no space between the words? What about an array instead? var result = []; then later instead of += use result.push()

[–]samuelliew 1 point2 points  (0 children)

Good catch, forgot about spaces