JavaScript parseInt | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

JavaScript parseInt

function convertToInteger(str) { parseInt(str); return parseInt; } convertToInteger("56"); I need to parse any number that enters the function. Please where i'm I wrong?

10th Oct 2018, 12:39 PM
Dzoyem Barry
Dzoyem Barry - avatar
4 Answers
+ 6
it should be... function convertToInt(n) { return parseInt(n); }
10th Oct 2018, 12:53 PM
Md. Nafis Ul Haque Shifat
Md. Nafis Ul Haque Shifat - avatar
+ 2
parseInt is a funcion, a function returns a value, and if u want tô return this value, you should to assign this function call to a var, for example: var prs = parseInt("3"); return prs; In your function, you returned parseInt func, not this return for "56" :p, I'm BR but.. I hope that u be able to understand ;w; srry
10th Oct 2018, 2:23 PM
HidekiHrk
HidekiHrk - avatar
+ 1
hello there. In your exemple you did return the parseInt function. You need return just value instead. Note: var str = '56'; var decimalNum = parseInt(str, 10); The ten number force decimal number.
12th Oct 2018, 2:33 AM
Mr Genesis
Mr Genesis - avatar
+ 1
Thank you friends 👊
14th Oct 2018, 6:03 AM
Dzoyem Barry
Dzoyem Barry - avatar