0

Whats wrong with this code

I want to print Name and Capital its giving me an error whats wrong WHY! function main() { var country = readLine(); var capital = readLine(); console.log(countryCard(country, capital)); } function countryCard(country, capital){ //complete the function //use backtick (` `) for template literal const name `Name: ${country}, Capital: ${capital}`; }

30th Apr 2021, 3:15 PM
Abdul Qadir
Abdul Qadir - avatar
9 ответов
0
Abdul Qadir You have to do like this console.log("Name: " + `${country}` + ", Capital: " + `${capital}`); or like this console.log(`Name: ${country}`+ ", " + `Capital: ${capital}`);
30th Apr 2021, 3:22 PM
A͢J
A͢J - avatar
+ 3
Abdul Qadir Both are working for me. I gave you solution after tried both. I think you are doing some mistakes.
30th Apr 2021, 3:42 PM
A͢J
A͢J - avatar
+ 2
Instead of using console.log, you need to use return (`Name: ${country}`+","+` Capital: ${capital}`); Since in the main you are already printing, you just need to return it
7th Jun 2022, 2:14 AM
Russell Sean Gonzalve
Russell Sean Gonzalve - avatar
0
Thank you i tried that. it is printing the answer but it is still saying undefined in next line and test case still fail 🤷🏻‍♂️why
30th Apr 2021, 3:26 PM
Abdul Qadir
Abdul Qadir - avatar
0
Nevermind i understand the logic. But tescases still failing thank you though. I tried both but not working
30th Apr 2021, 3:30 PM
Abdul Qadir
Abdul Qadir - avatar
30th Apr 2021, 5:00 PM
Matias
Matias - avatar
0
Yesh both are working but after that it is showing me undefined in next line.
1st May 2021, 4:13 PM
Abdul Qadir
Abdul Qadir - avatar
0
ES6 Variables and Strings
6th Oct 2021, 8:27 PM
Betty Chou
Betty Chou - avatar
0
That was my solution: function main() { var country = readLine(); var capital = readLine(); console.log(countryCard(country, capital)); } function countryCard(country, capital){ //complete the function //use backtick (` `) for template literal country= `Name: ${country}`; capital = `Capital: ${capital}`; return(country+", "+capital); }
5th Nov 2021, 10:36 AM
mstavra
mstavra - avatar