Skip to content
Advertisement

How do I send a character from a string that is NOT a letter or a number to the end of the string?

I am doing a Pig Latin code in which the following words are supposed to return the following responses:

JavaScript

However, for the last word, my code does not push the ‘!’ to the end of the string. What is the code that will make this happen?

All of them return the correct word apart from the last which returns “Ience!Scay!”

JavaScript

Advertisement

Answer

For simplicity, how about you check if the word contains an exlamation point ! at the end and if it does just remove it and when you are done add it back. So instead of returning just check place ! at the end (if you discovered it does at the beggining).

JavaScript

That way it does not treat ! as a normal letter and the output is Iencescay!. You can of course do this with any other character similarly

JavaScript
Advertisement