0

If i do something like:

console.log('a'+ '\n' + 
            'b'+  '\n' + 
            'c');

I will get in console:

`a
 b
 c`

but if i try to return it such as:

function letter() {
return 'a'+ '\n' + 
       'b'+  '\n' + 
       'c';
}
letter();

it prints out 'a\nb\nc'. how do i get the return to be the same as what it is in console.log only using the return statement?

it prints out fine in google developer console but i am using a console from repl.it so i guess it depends on how that console is formatted?

9
  • console.log(letter()); Also, your second code snippet doesn't print anything (unless you're typing directly into the console) Commented Mar 11, 2017 at 2:10
  • 1
    must depend on the browser - both codes produce Identical output in firefox (and why is the format of console output important at all) Commented Mar 11, 2017 at 2:12
  • i am trying to do it without using console.log at all. just with the return statement itself. Commented Mar 11, 2017 at 2:12
  • which browser? and why is it important? Commented Mar 11, 2017 at 2:13
  • 1
    This question makes no sense. The only way to print something is to use console.log (or console.error etc.) Commented Mar 11, 2017 at 2:16

2 Answers 2

2

Your code is fine at least in Firefox and Chrome.

console.log(letter()); should do exactly what you want.

If you are running into an issue, I would guess that it is because of your browser. Try in another browser.

update: i see your response "it's not a browser just a console in an environment on a website, it's just a javascript problem that wants me to print each of them on a new line".

Certainly, in a normal browser your code is fine. Maybe on this site, they planned you to solve this in a different mannor. This could be a bug.

Sign up to request clarification or add additional context in comments.

5 Comments

i am trying to do it without using console.log, just the return statement. i'm using console.log in the first place to show what it should look like but i am not sure if that is relevant even
ahh where is the website? Send me a link.
website is repl.it
Dude.. haha. send me a link to that puzzle. I am not going through the whole site.
well you could just type that in the developer console for any problem? also im not sure if you can access mine but it would be repl.it/student/submissions/622164
0

Try this way

function letter() {
return "a\nb\nc";
}
console.log(letter());

It requires double quotes

2 Comments

It doesn't require double quotes.
trying to do this without using console.log sorry

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.