+ 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?
19 Answers
+ 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));
+ 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.....
+ 3
Try:
function main(amount, rate) {
return amount * rate
}
var amount = parseFloat(readLine(), 10);
var rate = parseFloat(readLine(), 10);
console.log(main(amount, rate));
+ 2
Enigma , that is because convert function is undefined. You need to write it. It shall basically return amount*rate))
+ 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?
+ 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
+ 1
Go and learn multiplication first
Then learn about functions in JavaScript
+ 1
Enigma
No!
It doesn't require two functions. Where it is written ??
+ 1
The question requires logical reasoning
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));
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.
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
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
0
function main() {
var amount = parseFloat(readLine(), 10);
var rate = parseFloat(readLine(), 10);
var convert = amount*rate;
console.log(convert);
}
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));
}
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 .
- 1
But it's still error
It's not working
- 1
No. Just take rellot's screwdriver's code and just change
Return convert(amount, rate)
To
return amount*rate
- 3
🌀 Shail Murtaza شعیل مرتضیٰ 🤕😭
I've learnt it
The question is complicated