+ 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

12th Sep 2020, 10:20 AM
Nor'wester 🌪️ 🇧🇩 (INACTIVE)
Nor'wester 🌪️ 🇧🇩 (INACTIVE) - avatar
8 Réponses
+ 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!
12th Sep 2020, 10:25 AM
MSN
MSN - avatar
+ 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])
12th Sep 2020, 11:56 AM
Rei
Rei - avatar
+ 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
12th Sep 2020, 10:34 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
12th Sep 2020, 10:33 AM
MSN
MSN - avatar
+ 2
Thanks, MSN👑//INACTIVE, but it was easier to use split("(")[1]
12th Sep 2020, 10:34 AM
Nor'wester 🌪️ 🇧🇩 (INACTIVE)
Nor'wester 🌪️ 🇧🇩 (INACTIVE) - avatar
+ 2
🇧🇩🇳‌🇴‌🇷‌'🇼‌🇪‌🇸‌🇹‌🇪‌🇷‌ i know. u can use this method in future if u need.
12th Sep 2020, 10:36 AM
MSN
MSN - avatar
+ 1
Thanks, MSN👑//INACTIVE ,but that's only half the problem.
12th Sep 2020, 10:27 AM
Nor'wester 🌪️ 🇧🇩 (INACTIVE)
Nor'wester 🌪️ 🇧🇩 (INACTIVE) - avatar
+ 1
Never mind. Solved it. See the code again.
12th Sep 2020, 10:30 AM
Nor'wester 🌪️ 🇧🇩 (INACTIVE)
Nor'wester 🌪️ 🇧🇩 (INACTIVE) - avatar