Check if a word is present in a sentence | Function that returns true if the word is found ; To convert the word in uppercase ; To convert the complete sentence in uppercase ; To break the sentence in words ; To store the individual words of the sentence ; Comparing the current word with the word to be searched ; Driver code
function isWordPresent ( sentence , word ) { word = transform ( word ) ; sentence = transform ( sentence ) ; let s = sentence . split ( " " ) ; for ( let temp = 0 ; temp < s . length ; temp ++ ) { if ( s [ temp ] == ( word ) ) { return true ; } } return false ; } function transform ( word ) { return word . toUpperCase ( ) ; } let s = " " ; let word = " " ; if ( isWordPresent ( s , word ) ) document . write ( " " ) ; else document . write ( " " ) ;