Hi everyone,
Just like in the previous thread I created, it has to do with JavaScript 101 with Szolt. Before moving on to the next chapter of the videos, I decided to repeat the JavaScript part again. In the Input Output part where we code to get a message that we bought 1.15 BTC, I decided to use Number.parseInt instead of just a + for diversification and to remember this function too just in caae it would be useful at some point in time, although, + is so much more time saving to type.
const ticker = prompt(`Enter your crypto ticker: `);
const amount = Number.parseInt(prompt(`Enter the amount you want to buy: `));
console.log(`You have just bought ${amount}${ticker}`);
Now my problem with the code above is that this time by using parseInt, instead of + I tend to get the message “You have just bought 1 BTC” although in the amount I insert 1.15. I used the very same code and deleted the parselInt and replaced it with + and then indeed it displays 1.15 when I add 1.15 but when I specifically use parselInt it displays only a round number, 1 in this case.
Can someone tell me why is that? am I doing something wrong - although I doubt it since if I take the same very code and just delete parseInt and add + instead it displays just like I wish 1.15:
const ticker = prompt(`Enter your crypto ticker: `);
const amount = +prompt(`Enter the amount you want to buy: `);
console.log(`You have just bought ${amount}${ticker}`);
Thank you!