DEV Community

KaozDev
KaozDev

Posted on

Convert a Number or a String

Hi everyone, I'm new to the "React" javascript framework to improve my skills, I gave myself as an exercise to convert a number or string into a symbol. For example a number will convert like this and a string will convert like this <?L> I present to you my code that I was able to write to reach the end of my exercise on pastebin:
https://pastebin.com/uKeMM1zT

and here is the result I get in return
Alt Text

characters such as <?d> or <?L> do not appear as many times as the string inserted in the input

if I could get some help from the more experienced or someone who has any idea how to fix this it will warm my heart.
I've been looking for a solution on the internet for 3 days, but nothing solves my problem or maybe I'm not typing the right keywords.

Top comments (5)

Collapse
 
minterm0143 profile image
Minterm0143

I don't even know js but try this try to break the given string into char and run a loop until strlength for each iteration prink ?d

Collapse
 
kaozdev profile image
KaozDev

like this you mean?

//button
const [ConvertInput, setConvertInput] = useState();

const ConvertData = () => {
    for(let i=0; i<InputContain.length; i++){
        if(typeof InputState === 'string'){
            setConvertInput('?d')
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

the whole code on: pastebin.com/uKeMM1zT

Collapse
 
minterm0143 profile image
Minterm0143

Yeah some wt like this is it working?

Thread Thread
 
kaozdev profile image
KaozDev

absolutely not, it's been 3 days I imagined all kinds of algorithms to get there

Thread Thread
 
minterm0143 profile image
Minterm0143

Means wt you really need when your input is string it should print ?L and when it a number it should print ?d