0

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.");
}
Tushar
  • 85,780
  • 21
  • 159
  • 179
Samuel Ridicur
  • 59
  • 2
  • 10
  • You need to invoke the function `toUpperCase` by appending `()` in `var text = prompt("Paste Text Here").toUpperCase;`. **==>** `var text = prompt("Paste Text Here").toUpperCase();` – Tushar Nov 30 '15 at 05:08
  • toUpperCase is a function, you want `toUpperCase()` - the result of the function – Jaromanda X Nov 30 '15 at 05:08

1 Answers1

1
var text = prompt("Paste Text Here").toUpperCase;

you should call function

var text = prompt("Paste Text Here").toUpperCase()
Pavel Shirobok
  • 284
  • 1
  • 8