+ 1
JS 7.2 Exercise help
Hello, Can anyone help me with what I am doing wrong here... I have tried multiple solutions and every one has failed. It asks to output what the price would be with 20% off so I am multiplying the number times 80%(.8). I have tried return, output and console.log and none have worked for me. —- EXERCISE BELOW —— //so we don’t overwhelm you, we’ve hidden the code that executes the input function main() { var oldPrice = parseInt(readLine(), 10); // your code goes here //my code.... var newPrice = (oldPrice * .8); } //my code... console.log(main(newPrice));
5 Respostas
0
Nevermind, I just found out that I need to put the “console.log” inside the curly braces instead of outside.
0
You're calling a main function which has no parameter and at the same time invoking it with argument (newPrice) which is not define.
See the correct simple version of it below:
function main() {
var oldPrice = parseInt(readLine(), 10);
// your code goes here
//my code....
var newPrice = (oldPrice * .8);
return newPrice;
}
//my code...
console.log(main());
Can you see the differences?
Note:
The newPrice you declared in your main function is a local scope. That's why the newPrice is not define when you try to pass it as an argument to the main function which too has no parameter.
Hope it helps?
0
send me that version if you won't mind please
0
This is what I had submitted and it worked...
//so we don’t overwhelm you, we’ve hidden the code that executes the input
function main() {
var oldPrice = parseInt(readLine(), 10)
// your code goes here
var newPrice = (oldPrice * .8)
console.log(newPrice)
}
0
Yeah this would work because newPrice is defined and you're not passing an argument to the main function when invoking it i.e main();
It's similar to my work on my first respond. The only different is I return instead of console.log