Currently, I am in the process of developing a program that can determine if an input string includes a period, question mark, colon, or space. If these punctuation marks are not present, the program will return "false". However, if any of them are found, the program will output all characters before the first instance of the punctuation. For example, given the string "grey cat", the program should return "grey" because it encountered a space. Is it possible to use logical OR operators in Javascript? I would prefer a solution without utilizing built-in functions, and efficiency is not a priority.
Update: The current version of the program is only displaying the original string. How can I modify it to print only the characters that appear before any punctuation?
function find_punctuation(str){
let result = "";
for (let i = 0; i < str.length; i++ ){
if (str[i] === "." || str[i] === "?" || str[i] === "" || str[i] === ","){
break;
} else {
result += str[i];
}
}
return result;
}
console.log(find_punctuation('he. y'));