When searching through an array how do we deal with white spaces? Do we say a search returns false if the user types in nothing (i.e. just presses enter) or types in a blank space?
test_pages=[
"Lorem Ipsum is simply dummy text of the printing and typesetting industry."
,
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout",
"There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable."
]
var find=prompt("Enter a term");
find = find.toLowerCase();
for(i=0;i<test_pages.length;i++)
{
// normalisation
test_pages[i] = test_pages[i].toLowerCase();
// use indexOf() to find the occurrences of pattern
if(test_pages[i].indexOf(find)>=0)
{
alert("true");
break;
}
else if(test_pages[i].indexOf(find)<0)
{
alert("false");
}
}
Well you should validate the input and request that the user actually types something inside. If that isn’t possible, either response is logical and it won’t have any different impact on the user experience