+ 2
Problem with parseInt.
Why am I getting NaN instead of 45? And "how" to get 45 here? https://code.sololearn.com/Wjg3738JvYaE/?ref=app
8 Respostas
+ 10
parseInt only works on text that has numbers at first.
Like parseInt('ja12') will return NaN but parseInt('12ja') will return 12.
I hope u understood.
Happy coding!
+ 5
i know its solved but i'll just throw it here in case someone needs it
the opposite approach from Мг. Кнап🌠
parseInt(x.style.transform.match(/\d+/)[0])
+ 3
🇧🇩🇳🇴🇷'🇼🇪🇸🇹🇪🇷 when you are accessing element.style.transform property you are getting rotate(45deg) and as MSN👑//INACTIVE has suggested on parseInt you will get NaN, that's the defined behaviour of parseInt
Although it you actually want to get the 45 number value from that string, you can use regex
console.log(parseInt(x.style.transform.replace(/\D/g,"")));
https://code.sololearn.com/WqXR1LDGF6QS/?ref=app
+ 2
updated version:
https://code.sololearn.com/W2DaAIILBfCU/?ref=app
+ 2
Thanks, MSN👑//INACTIVE, but it was easier to use split("(")[1]
+ 2
🇧🇩🇳🇴🇷'🇼🇪🇸🇹🇪🇷 i know.
u can use this method in future if u need.
+ 1
Thanks, MSN👑//INACTIVE ,but that's only half the problem.
+ 1
Never mind. Solved it. See the code again.