Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Else If

Status
Not open for further replies.

dlyles

Programmer
Oct 13, 2002
24
US
Hey everybody. let me say that I'm a javascript newbie. I'm an asp and php kind of person. I have the below code that is giving me a syntax error. My novice eye says it's ok, obviously not.

It's supposed to work like so...if the url is the referenced url than cmi.score.scaled >= and if that's the case than the other two conditions. Ok, does this make sense?


else
{
if(document.location.href='../../../Module_5/M5_01_scenario/m5_01_scenario.html');
{
(name=="cmi.score.scaled" && value >= .50);
LMSSetValue("cmi.completion_status","completed");
LMSSetValue("cmi.progress_measure",1);
}
else
{
if(document.location.href='../../../Module_5/M5_02_scenario/m5_02_scenario.html');
{
(name=="cmi.score.scaled" && value >= .50);
LMSSetValue("cmi.completion_status","completed");
LMSSetValue("cmi.progress_measure",1);
}
else
{
if(name=="cmi.score.scaled" && value >= .75);
{
LMSSetValue("cmi.completion_status","completed");
LMSSetValue("cmi.progress_measure",1);
}
{

var result = api.SetValue(name, value);
if (result.toString() != "true")
{
throw(ErrorHandler("LMSSetValue("+name+","+value+") failed.",227));
}
else
{
print_info("LMSSetValue("+name+","+value+") succeeded.","APIWrapper.js",232);
}
}

return;
}
 
Any decent PHP programmer should know that in an if you need to use the double equals (==). You use the assignment operator TWICE inside if statements.

Lee
 
Your opening and closing braces appear to be unbalanced, as well. They're difficult to count the way you have them indented.

Lee
 
While I'm tackling things a piece at a time, what is this?
Code:
(name=="cmi.score.scaled" && value >= .50);

You have that twice in your code.

Lee
 
And this probably won't work unless both name and value are numeric values.
Code:
"LMSSetValue("+name+","+value+") succeeded/failed."

Lee
 
Thanks, I have it twice because it is the condition on two ifs.
 
No, it's not. In the code you showed in your original post, there are no ifs in front of that code.

If your code isn't copied and pasted in here, please ONLY do that. There's no point in troubleshooting code you haven't copied and pasted because of possible errors, or possibly excluding errors in the actual code.

Lee
 
So true, and my apologies

function LMSSetValue(name, value)
{
print_info("LMSSetValue("+name+","+value+") called.", "APIWrapper.js", 216);
var api = getAPIHandle();
if (api == null)
{
print_info("Unable to locate the LMS's API Implementation.\nInitialize was not successful.", "APIWrapper.js", 220);
throw(_GeneralException);
}
else
{
if(document.location.href='../../../Module_5/M5_01_scenario/m5_01_scenario.html');
{
(name=="cmi.score.scaled" && value >= .50);
LMSSetValue("cmi.completion_status","completed");
LMSSetValue("cmi.progress_measure",1);
}
else
{
if(document.location.href='../../../Module_5/M5_02_scenario/m5_02_scenario.html');
{
(name=="cmi.score.scaled" && value >= .50);
LMSSetValue("cmi.completion_status","completed");
LMSSetValue("cmi.progress_measure",1);
}
else
{
if(name=="cmi.score.scaled" && value >= .75);
{
LMSSetValue("cmi.completion_status","completed");
LMSSetValue("cmi.progress_measure",1);
}
{

var result = api.SetValue(name, value);
if (result.toString() != "true")
{
throw(ErrorHandler("LMSSetValue("+name+","+value+") failed.",227));
}
else
{
print_info("LMSSetValue("+name+","+value+") succeeded.","APIWrapper.js",232);
}
}

return;
}
 
All my previous statements about the errors in your code stand. Your real code actually DOES have all that mess in it. Try using Firefox and view the error console to get an idea of some of the errors.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top