+ 3

You are making a currency converter app. Create a function called convert, which takes two parameters: the amount to convert,

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 main() { var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); console.log(convert(amount, rate)); } Who can help with this?

28th Sep 2021, 11:49 AM
Enigma
Enigma - avatar
19 ответов
+ 6
you didn't even put the parameters, let alone return function main(var amount, var rate){ return convert(amount, rate) } var input1 = praserFloat(readLine(), 10) var input2 = praserFloat(readLine(), 10) console.log(main(input1, input2));
28th Sep 2021, 11:57 AM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 4
If you want two functions here you go: function convert(amount, rate){ return amount*rate; } function main() { var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); console.log(convert(amount, rate)); } But who cares.....
29th Sep 2021, 6:02 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 3
Try: function main(amount, rate) { return amount * rate } var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); console.log(main(amount, rate));
28th Sep 2021, 4:17 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 2
Enigma , that is because convert function is undefined. You need to write it. It shall basically return amount*rate))
28th Sep 2021, 12:42 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
Aleksei Radchenkov function main(42, 0.72) { var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); function convert(){ return amount * rate; } console.log(convert(amount, rate)); } Like this?
28th Sep 2021, 3:35 PM
Enigma
Enigma - avatar
+ 1
Aleksei Radchenkov function main(amount, rate) { return amount * rate var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); } console.log(main(42, 0.72)); It returned the actual answer but it's saying not correct
28th Sep 2021, 4:13 PM
Enigma
Enigma - avatar
+ 1
Go and learn multiplication first Then learn about functions in JavaScript
28th Sep 2021, 6:13 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
+ 1
Enigma No! It doesn't require two functions. Where it is written ??
29th Sep 2021, 6:01 AM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
+ 1
The question requires logical reasoning
8th Oct 2022, 1:32 PM
Olafare Moyo
Olafare Moyo - avatar
0
Aleksei Radchenkov I don't know where to place the given input in his code That's 42 and 0.72 function main(var amount, var rate){ return amount * rate } var input1 = praserFloat(readLine(), 10) var input2 = praserFloat(readLine(), 10) console.log(main(input1, input2));
28th Sep 2021, 3:46 PM
Enigma
Enigma - avatar
0
First of all you forgot '}' at the end Secondarily, you should input your user input through console. They will then be assigned to input1 and input2 relatively.
28th Sep 2021, 3:54 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
0
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. Aleksei Radchenkov it requires two functions, the first ones is right but the function to make the code work is what I don't understand
29th Sep 2021, 5:58 AM
Enigma
Enigma - avatar
0
Enigma If you really want to be a good programmer then learn programming. Don't just copy and paste other's codes. If not then go ahead. Keep doing what you are doing right now
29th Sep 2021, 6:06 AM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
0
function main() { var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); var convert = amount*rate; console.log(convert); }
29th Sep 2021, 1:21 PM
Мария Волкова
Мария Волкова - avatar
0
You can try this function main() { var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); function convert(){ return amount * rate; } console.log(convert(amount, rate)); }
29th Sep 2021, 3:25 PM
Hamza Akburak
Hamza Akburak - avatar
0
function convert(amount, rate){ return amount*rate; } function main() { var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); console.log(convert(amount, rate)); } This is the exact answer .
15th Feb 2023, 7:44 AM
Jembere Guta
Jembere Guta - avatar
- 1
But it's still error It's not working
28th Sep 2021, 12:12 PM
Enigma
Enigma - avatar
- 1
No. Just take rellot's screwdriver's code and just change Return convert(amount, rate) To return amount*rate
28th Sep 2021, 3:41 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
- 3
🌀 Shail Murtaza شعیل مرتضیٰ 🤕😭 I've learnt it The question is complicated
29th Sep 2021, 5:50 AM
Enigma
Enigma - avatar