Reputation: 59
I was playing around with javascript trying to make a word searcher for strings. However, when i run the code i get TypeError: text.indexOf is not a function. I don't think there is a syntax error, or maybe i am completly missing something.
var text = prompt("Paste Text Here").toUpperCase;
var word = prompt("What word would you like to search for?").toUpperCase;
var hits = [];
var n = text.indexOf(word);
hits.push(text[n]);
if (hits.length === 0) {
console.log("Your word could not be found.");
} else {
console.log("Your word was found " + hits.length + " times.");
}
Upvotes: 0
Views: 1101
Reputation: 307
var text = prompt("Paste Text Here").toUpperCase;
you should call function
var text = prompt("Paste Text Here").toUpperCase()
Upvotes: 1