+ 1
Spend before Saving
I have no clue what I'm doing with this can someone please explain what to do, it keeps saying that salaryAmount is not defined, but I don't understand how it's not?? "Do not save what is left after spending; instead spend what is left after saving", said Warren Buffett. Inspired by this words, Jack decided to save 15% of his monthly salary. You are given a program that takes salary as input. Complete the function in order to calculate and output the savings. function main() { var salaryAmount = parseInt(readLine(), 10); // complete the function call getSavings(); } //complete the function function getSavings() { };
21 Antworten
+ 5
you are getting error of "salaryAmount is not defined", because.......
you haven't try to write incomplete code. The given lines of codes are hints for you to complete
+ 2
SuperKitsune94 ahh fair enough, I'm very new to coding, but I'll explain my thought process, so obviously salaryAmount will change each time, all we want to do is do salaryAmount times by 0.15 to give 15% of the salaryAmount. You want this to be a function though, so you need something in the function that can be reused (e.g. getSavings(amount)). Then when you call the function with getSavings(salaryAmount), it substitutes the word amount in the code for salaryAmount, which the gets times be 0.15, but we need a variable to assign this to which I called savings, and then I return the value of savings to the console. I hope this helped but as I said Im really new to it all
+ 1
I don't get any error saying salaryAmount is not defined.
+ 1
function main() {
var salaryAmount = parseInt(readLine(), 10);
// complete the function call
getSavings(salaryAmount);
}
//complete the function
function getSavings(amount) {
savings = amount * 0.15
console.log(savings)
};
+ 1
I think just over two weeks
+ 1
The easiest way to solve this challenge is to use the user input directly into the function and complete the math inside the console.log
function main() {
var salaryAmount = parseInt(readLine(), 10);
// complete the function call
getSavings(salaryAmount);
}
//complete the function
function getSavings(salaryAmount) {
console.log(salaryAmount * 0.15)
};
+ 1
function main() {
var salaryAmount = parseInt(readLine(), 10);
// complete the function call
getSavings(salaryAmount);
}
//complete the function
function getSavings(getSavings) {
getSavings = salaryAmount*0.15;
console.log(getSavings);
};
hi,
I came up with the same code, but it doesn't pass the challenge, I tried other solutions proposed in the chat, but it doesn't seem to work. Do you have any idea what could be the problem? So far I didn't have any problems using Chrome. Thanks in advance :)
+ 1
@Brigi
in line 7 you need to change "(getSavings)" to "(salaryAmount)"
+ 1
function main() {
var salaryAmount = parseInt(readLine(), 10);
// complete the function call
getSavings(salaryAmount);
}
//complete the function
function getSavings(salaryAmount) {
var percentageSavings = .15;
console.log(salaryAmount * percentageSavings);
};
0
What did you put for it?
0
Sorry i don't get what you mean, I copy pasted the above code in node playground for code coaches and got no error saying "salaryAmount is not defined " . I would have tested the code myself if i had access to it.
0
Yeah I actually just did it like a minute ago, im glad I finally get it
0
Adamjhw This doesn't work
0
function main() {
var salaryAmount = parseInt(readLine(), 10);
// complete the function call
getSavings(salaryAmount);
}
//complete the function
function getSavings(amount) {
savings = amount * 0.15
console.log(savings)
};
this is copy and pasted from the code section and it comes up with all ticks for me, sorry if it is wrong though, not trying to spread false info or anything, just my best attempt that gave me ticks
SuperKitsune94
0
I'm new to coding as well haha Adamjhw how long have you been doing it? Thanks for your advice!
0
why cant i do somthing like this:
function main() {
var salaryAmount = parseInt(readLine(), 10);
// complete the function call
console.log(getSavings(salaryAmount));
}
//complete the function
function getSavings(salaryAmount) {
return salaryAmount * 0.15
};
0
function main() {
var salaryAmount = parseInt(readLine(), 10);
// complete the function call
getSavings(salaryAmount);
}
//complete the function
function getSavings(parameter) {
parameter = parameter * 0.15
console.log(parameter);
};
0
function main() {
var salaryAmount = parseInt(readLine(), 10);
// complete the function call
getSavings(salaryAmount);
}
//complete the function
function getSavings(salaryAmount) {
salary=salaryAmount*0.15;
console.log(salary);
};
0
function main() {
var salaryAmount = parseInt(readLine(), 10);
// complete the function call
getSavings(salaryAmount);
}
//complete the function
function getSavings(salaryAmount) {
result= salaryAmount * 0.15
console.log(result);}