M
Matt L.
In summary, I don't know how/why the following code works and would like to
know.
I'm trying to match the first 3 characters of a variable (filename). The
code below crudely works, but only if I move "Activities" below "Fine Arts",
implying the code is not matching exactly the first 3 characters. I've left
the code in my testing state for the following questions:
1. How do I specifiy the match to include all 3 characters (not just a
single character match)?
2. What's the difference between 'indexOf' and 'search'? (I left both in the
code below)
3. What function does the operator and following number perform in the 'if'
statements? (I left both operators in the code below)
4. Am I on the right track using if/else if? Is this economical?
Any comments are warmly and eagerly welcome.
Thanks in advance for your help,
Matt
function searchResult(filename, myitemtext) {
var valu = filename;
Str=valu;
Str=Str.substring(3,Str.length-1);
for (var i = 0; i<Str.length; i++)
{
if(valu.indexOf("hh") !=-1)
alert("Heritage Hall");
else if(valu.search( "fa1" ) > -1)
alert("Fine Arts - First Floor");
else if(valu.search( "fa2" ) > -1)
alert("Fine Arts - Second Floor");
else if(valu.search( "fa3" ) > -1)
alert("Fine Arts - Third Floor");
else if(valu.search( "a1" ) > -1)
alert("Activities - First Floor");
else if(valu.search( "a2" ) > -1)
alert("Activities - Second Floor");
else if(valu.search( "a3" ) > -1)
alert("Activities - Third Floor");
else if(valu.indexOf("b")!=-1)
alert("Business");
else if(valu.indexOf("dc")!=-1)
alert("Daycare");
}
know.
I'm trying to match the first 3 characters of a variable (filename). The
code below crudely works, but only if I move "Activities" below "Fine Arts",
implying the code is not matching exactly the first 3 characters. I've left
the code in my testing state for the following questions:
1. How do I specifiy the match to include all 3 characters (not just a
single character match)?
2. What's the difference between 'indexOf' and 'search'? (I left both in the
code below)
3. What function does the operator and following number perform in the 'if'
statements? (I left both operators in the code below)
4. Am I on the right track using if/else if? Is this economical?
Any comments are warmly and eagerly welcome.
Thanks in advance for your help,
Matt
function searchResult(filename, myitemtext) {
var valu = filename;
Str=valu;
Str=Str.substring(3,Str.length-1);
for (var i = 0; i<Str.length; i++)
{
if(valu.indexOf("hh") !=-1)
alert("Heritage Hall");
else if(valu.search( "fa1" ) > -1)
alert("Fine Arts - First Floor");
else if(valu.search( "fa2" ) > -1)
alert("Fine Arts - Second Floor");
else if(valu.search( "fa3" ) > -1)
alert("Fine Arts - Third Floor");
else if(valu.search( "a1" ) > -1)
alert("Activities - First Floor");
else if(valu.search( "a2" ) > -1)
alert("Activities - Second Floor");
else if(valu.search( "a3" ) > -1)
alert("Activities - Third Floor");
else if(valu.indexOf("b")!=-1)
alert("Business");
else if(valu.indexOf("dc")!=-1)
alert("Daycare");
}