21 Day Coding Challenge

Challenge 20: Need Help

#1

Can anyone please let me know what I m doing wrong her?

#2

@tim_lhl @Seb any idea what I am missing here? I placed single quotes around my numbers in if statements but still not working.

#3

Your last statement, is essentially saying, if non of those other conditions apply, then apply this last one. Instead, it should be if this last condition also doesn’t apply, then do nothing to it. Hopefully that makes sense.

You should also ‘return’ something at the end.

#4

Is this what you meant? Still no luck, perhaps I didn’t understand what you meant.

#5

Now you’re only returning the charaAt(i)
Return it once it checked the whole array :slight_smile:

1 Like
#6

So it should return in the big if statement not the nested ones?

#7

Yep, you got it.

Now, ‘return’ will end the function, so you only want to do that after you’ve processed the whole string.

#8

Somehow it still didn’t workout.

#9

Oh and your return is in the loop

Also just a quick insight on you’re code!
I’m not 100% sure since i can’t test it,
but instead of replacing only the [ .charAt(i) ] !~
Wouldn’t it be better to replace all the let say 1 with i in the string directly !
This way you wont have to go over another 1 again :thinking: .

#10

There are a couple issues here:

Number.isInteger doesn’t do what you think it does. Either use it in conjuction with parseInt or use isNaN

And secondly your current equality checks will never result in true

1 Like
#11

To add to what all these nice people are saying…

Will that test true or flase?

Number.isInteger("0")

1 Like
#12

I take it back lmao
i was wrong hahaha

https://www.w3schools.com/code/tryit.asp?filename=G49EEE3Q9PY8

1 Like
#13

Looks like I had my Equality all wrong all along,
the more you know :thinking: !

1 Like
#14

Still no luck. :pleading_face:

#15

You’re still returning something every time the loop goes around. You need to get return out of the loop.

1 Like
#16

Sounds right, but didn’t workout.

#17

Ok, you’re making progress!

As @Seb suggested, take a look at his link regarding the ‘===’ and ‘==’.

#18

Get ready for some wizardry with the ascii table
Try on your first if ! :mage:

if(message.charCodeAt(i) >= 48 && message.charCodeAt(i) <= 53 )

temp

#19

The message you are returning is the same as the message that is passed through in the function parameters.

Strings in JavaScript are immutable

https://thecodebarbarian.com/string-replace-in-javascript.html

1 Like
#20

Yeah I tried using just - but then yellow triangle appeared and said, use ‘===‘ to compare with ‘0’