JavaScript: Multiline strings
Template literals preserve line breaks naturally.
const text = `Line 1
Line 2
Line 3`;Each physical line break becomes a \n in the string.
Instructions
Create a variable email with multiline text and print it:
Dear customer!
Your order has been accepted.
Expected delivery: 3 business days.Tips
If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:
- Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
Your exercise will be checked with these tests:
// @ts-check
import { expect, test, vi } from 'vitest';
test('multiline strings', async () => {
const consoleLogSpy = vi.spyOn(console, 'log');
await import('./index.js');
const firstArg = consoleLogSpy.mock.calls.join('\n');
expect(firstArg).toBe(
'Dear customer!\n\nYour order has been accepted.\nExpected delivery: 3 business days.',
);
});Teacher's solution will be available in:
20:00
