+ 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: `);

1st Dec 2023, 6:01 PM
Nliaustemac
Nliaustemac - avatar
9 Respostas
+ 2
Please review the lesson. How do you declare a template literal? What variables are there already?
1st Dec 2023, 6:55 PM
Ausgrindtube
Ausgrindtube - avatar
+ 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.
3rd Dec 2023, 12:09 AM
Joel Ende Nathaniel
Joel Ende Nathaniel - avatar
+ 3
You don't need to know. But it's to accept input.
1st Dec 2023, 8:11 PM
Ausgrindtube
Ausgrindtube - avatar
+ 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}`);
1st Dec 2023, 9:00 PM
Nliaustemac
Nliaustemac - avatar
+ 3
Thank you all, am sorted!
2nd Dec 2023, 10:53 AM
Nliaustemac
Nliaustemac - avatar
+ 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}`);
3rd Dec 2023, 6:57 AM
SUJAN
SUJAN - avatar
+ 2
Ausgrindtube Please, i don’t understand why readline() is asign to country and capital variables . Could you explain
1st Dec 2023, 7:26 PM
Nliaustemac
Nliaustemac - avatar
+ 2
let country=readLine(); let capital= readLine(); console.log(`Country:${country},Capital:${capital}`);
2nd Dec 2023, 9:43 AM
Med Yassine
Med Yassine - avatar
+ 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.
6th Dec 2023, 12:37 AM
Marcelino Arias
Marcelino Arias - avatar