Im writing a program that will tell you if the input string contains a period, question mark, colon or space. If it doesn't it'll return "false". If it does, it'll return all of the characters before the found punctuation. Ex. str= "grey cat", program will return "grey" because it was stopped by the space. Can I use "or" in Javascript? EDIT Im trying to do this without any built-in functions. Im not looking for an efficient way
update - now it's just printing the str. How do I get it to just print what comes before the punctuation (if any)
function find_punctuation(str){
let result = "";
for (let i = 0; i < str.length; i ++ )
if (str[i] === "." || str[i] === "?"|| str[i] === "" || str[i] === ","){
}
else result += str[i]
return result
}
console.log(find_punctuation('he. y'));