+ 1
I need help with this code about template literal on JavaScript.
let country = readLine(); let capital = readLine(); //complete the code console.log(`Country: , Capital: `);
9 ответов
+ 2
Please review the lesson. How do you declare a template literal?
What variables are there already?
+ 6
It seems like you're trying to create a template literal in JavaScript to display the values of the country and capital variables. You can simply insert the variables into the template literal like this:
javascript
Copy code
let `country `= readLine();
let `capital` = readLine();
// complete the code
console.log(`Country: ${country}, Capital: ${capital}`);
In the template literal, you use ${} to insert the values of the variables into the string. This way, when you run the console.log statement, it will print the values of country and capital along with the specified text.
+ 3
You don't need to know. But it's to accept input.
+ 3
Please, Ausgrindtube what do you think about this code?
let country = 'France';
let capital = 'Paris';
//complete the code
console.log(`Country: ${country}, Capital: ${capital}`);
+ 3
Thank you all, am sorted!
+ 3
To include the variables 'country' and 'capital' inside the template literal, you can simply place them within the '${}' placeholders.here we go like this
let country = readLine();
let capital = readLine();
// complete the code
console.log(`Country: ${country}, Capital: ${capital}`);
+ 2
Ausgrindtube Please, i don’t understand why readline() is asign to country and capital
variables . Could you explain
+ 2
let country=readLine();
let capital= readLine();
console.log(`Country:${country},Capital:${capital}`);
+ 2
// We are asking the user to enter a country and a capital
let country = readLine();
let capital = readLine();
// Now, we want to display that information in the console in a pretty way
console.log(`Country: ${country}, Capital: ${capital}`);
We use backticks (` `) to create a 'template literal'. Inside it, ${country} and ${capital} act like placeholders that will be filled with the actual values the user entered. Then, the console.log() will display 'Country: [value of country], Capital: [value of capital]' in the console.