Hey; I’m really new to coding. I just made a simple calculator; user inputs a number and the output is a function of that number. However, I would like to modify it so that if a user inputs a number with spaces or commas (for example, “100,000” instead of “100000”), the function will still work. Any thoughts?
-
Get the value from input.
-
Manipulate the vlaue before putting it into your function for calculation.
-
Calculate your new manipulated input.
-
Get value from input…
$w('#input1').onChange(()=>{
let myValue = $w('#input1').value;
});
- Manipulation…
$w('#input1').onChange(()=>{
let myValue = $w('#input1').value;
let myManipulatedValue = myValue. ......... //<-- manipulation-process here!
});
a) Split-Manipulation…
.split() ---> myManipulatedValue = myValue.split(","); console.log(myManipulatedValue);
b) .slice()-manipulation-method
c) .trim()-manipulation-method
d) .substring()-manipulation-method
e) and so on…
!!! FIND THE RIGHT → STRING-MANIPULATION-METHOD !!!
And the rest of how to get your end-result is pure logic!
Good luck!