+ 1

Javascript project 3 problem

You are making a currency converter app. Create a function called convert, which takes two parameters: the amount to convert, and the rate, and returns the resulting amount. The code to take the parameters as input and call the function is already present in the Playground. Create the function to make the code work. Sample Input: 100 1.1 Sample Output: 110 function convert(amount,rate){ let x = amount*rate; console.log(x); } function main() { var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); console.log(convert(amount, rate)); } //now this whole code is giving me correct answer with undefined under the correct answer. But when i do return, instead of console.log(x). It gives me perfect answer without undefined written under.

1st Sep 2022, 5:24 PM
Ashish Sharma
Ashish Sharma - avatar
4 Respostas
+ 1
Hi! Just delete console.log from your last line, and call function itself.
1st Sep 2022, 5:36 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Yaroslav Vernigora okay thanks
2nd Sep 2022, 4:01 AM
Ashish Sharma
Ashish Sharma - avatar
+ 1
This is the Answer of your question: function main() { var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); console.log(convert(amount, rate)); } function convert(amount, rate){ return amount*rate; }
3rd Sep 2022, 4:10 AM
Ahmad Zubair Afghanmal
0
Ahmad Zubair Afghanmal i figured out the answer, my question is why there was an undefined error in the first place.
3rd Sep 2022, 7:11 AM
Ashish Sharma
Ashish Sharma - avatar