0

Please what's wrong with this code

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 let msg = `${country}, Capital: ${capital}`; console.log(msg); } It's supposed to take country and capital as input and output it in a particular format. E.g France Paris Output France, Capital: Paris But what I'm getting is France, Capital: Paris Undefined

11th Aug 2021, 12:08 PM
Davies Olaniyi
Davies Olaniyi - avatar
4 ответов
+ 3
Davies Olaniyi you are using console.log two times on the same output . When the function is called it logs the output itself . But when you use console.log again on function call it returns undefined since function returned nothing . So either return the msg from the function and then use console.log on function call or simply call the function with no console.log
11th Aug 2021, 12:37 PM
Abhay
Abhay - avatar
+ 3
I don't know what it asks to do but i guess it is missing string Country in msg.
11th Aug 2021, 12:19 PM
Abhay
Abhay - avatar
+ 1
Abhay Thanks a bunch. I called it with return and it worked
11th Aug 2021, 12:51 PM
Davies Olaniyi
Davies Olaniyi - avatar
0
It's supposed to take country and capital as input and output it in a particular format. E.g France Paris Output France, Capital: Paris But what I'm getting is France, Capital: Paris Undefined
11th Aug 2021, 12:23 PM
Davies Olaniyi
Davies Olaniyi - avatar