Skip to content
Help Please!
Profile icon

Write a progra that validates a word typed in is not too exciting by checking for exclamation marks or hastags. If neither s present, then the sentence is good.
Enter Word: B0o!
TOo exciting
Enter sentence: #Moo
Too Exciting
Enter sentence: Hello

You are viewing a single comment. View All
Profile icon

You will need to be more specific about what language you are using. Many languages have an indexOf (or similarly named) method that can be used on strings to find the index of a string within a string (or if the string is not inside the string it usually returns -1, which is why this will be useful for you).

Some examples in different languages:


function validate(str) { return str.indexOf("#") == -1 && str.indexOf("!") == -1 ? "Good" : "Too exciting"; }


def validate(str): return "Good" if str.find("#") == -1 & str.find("!") == -1 else "Too exciting"


std::string validate(std::string str) { return str.find("!") == std::string::npos && str.find("#") == std::string::npos ? "Good" : "Too excited"; }


string validate(string str) { return str.IndexOf("!") == -1 && str.IndexOf("#") == -1 ? "Good" : "Too excited"; }

And I could go on...