Javascript discount calculator | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Javascript discount calculator

Canā€™t find the issue for the life of me. What am i doing wrong? function main(input) { var oldPrice = parseInt(input, 10) // Your code here var discount = (0.2 * oldPrice); var oldPrice = (oldPrice - discount); document.log(oldPrice); }

3rd Oct 2020, 5:39 AM
Sasquatch6ft40
13 Respostas
+ 5
console.log is used to display something in the console, useful for debbuging purposes. document.write is an evil thing that browsers provide to override the content of a web page, please avoid it. "document" object is only available on browsers, SoloLearn's in-course challenges run in node.js playground, that's why document won't work.
3rd Oct 2020, 5:52 AM
Kevin ā˜…
+ 2
Share your code. Open a new question or link it here if you want. Sasquatch6ft40 You can send your suggestion using the in-app feedback option. It's in the menu.
3rd Oct 2020, 6:07 AM
Kevin ā˜…
+ 2
Oh, now I can see what you did. At line 2: inputString should be an empty string: let inputString = ""; Forget about the given code(it's just boilerplate to take input in node) and focus on the "//your code goes here:" part. Don't change anything else.
3rd Oct 2020, 6:18 AM
Kevin ā˜…
+ 1
document.log ?
3rd Oct 2020, 5:44 AM
Kevin ā˜…
+ 1
ohh console.log or document.write. well whats the difference between those two?
3rd Oct 2020, 5:45 AM
Sasquatch6ft40
+ 1
ok.. that kinda makes sense. im stuck on the very next quiz now though, ive already done the whole course and i still feel like they havent explained what i need to know for the challenges in the beginning.
3rd Oct 2020, 5:54 AM
Sasquatch6ft40
+ 1
Don't worry. Review the complete lesson where the challenge is located and you'll see what you need to know.
3rd Oct 2020, 6:02 AM
Kevin ā˜…
+ 1
process.stdin.setEncoding('utf-8'); let inputString = 'name = oldpass type text'; let currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { inputString = inputString.replace(/\s*$/, '') .split('\n') .map(str => str.replace(/\s*$/, '')); main(); }); function readLine() { return inputString[currentLine++]; } function main() { var oldPass = readLine(); var newPass = readLine(); // Your code here console.log(newPass !== oldPass) } just caught the missing semicolon, but it didnt make a difference as thats something else that only seems to matter sometimes.
3rd Oct 2020, 6:07 AM
Sasquatch6ft40
+ 1
i got it by changing !== to ===, but i swear i had tried that before i even posted. idk, maybe im too tired to try this tonight. thanks for the help tho man!
3rd Oct 2020, 6:27 AM
Sasquatch6ft40
0
is that not a thing? i coulda sworn it had me do that on the last quiz
3rd Oct 2020, 5:44 AM
Sasquatch6ft40
0
iā€™ve been looking for a while now... itā€™s the password one, and i can only solve one half the tests or the other half depending on if i use != or ===
3rd Oct 2020, 6:03 AM
Sasquatch6ft40
0
it would be extremely helpful if they changed the color of text that referred to nameholders. like, var name = hi, if name was a different color so you would know you dont need the word ā€˜nameā€™ to specify the type of variable, but that itā€™s whatever you want to name that variable.
3rd Oct 2020, 6:06 AM
Sasquatch6ft40
0
i didnā€™t change anything else. :( thatā€™s definitely not cool. ill see if that fixes it. nah, that returned them all as failed. if it helps, the ones i can see that i failed failed bc of a capitalized letter. i thought doing !== instead of != would fix it, but it didnt.
3rd Oct 2020, 6:22 AM
Sasquatch6ft40