-2
私はここで苦労しています。私のJSは以下の通りです。 目的はここです - ユーザーはコースのタイプを選択します - WSまたはAC。 オンサイトがチェックされている場合は、AC値をコース重量で1.5に更新します。JS変数とIF ELSE
人数は、ACまたはWSが選択されているかどうかによって値が異なります。したがって、Calculate Total関数には、コースタイプ値(ACまたはWS)を見直すifステートメントがあります。
JSHintがライン257で報告しています - 条件式が必要で、代りに割り当てが必要です。
//Set up an associative array
//The keys represent the size/weightof the course type
//The values represent the weight of the course type
var course_weight = [];
course_weight["AC"]=1;
course_weight["WS"]=1;
//Set up an associative array
//The keys represent the size/weightof the course type
//The values represent the weight of the course type
var course_type = new Array();
course_type["AC"]="AC";
course_type["WS"]="WS";
//Set up an associative array
//The keys represent the number of days
//The value represents the number of days
//We use this this array when the user set the number of days from the form
var number_days= new Array();
number_days["None"]=0 ;
number_days["1"]=1 ;
number_days["2"]=2 ;
number_days["3"]=3 ;
number_days["4"]=4 ;
number_days["5"]=5 ;
//Set up an associative array
//The keys represent the number of AC people
//The value represents thenumber of people
//We use this this array when the user set number of people from the form
var ACnumber_people= new Array();
ACnumber_people["None"]=0;
ACnumber_people["1"]=1;
ACnumber_people["2"]=2;
ACnumber_people["3"]=3;
ACnumber_people["4"]=4;
ACnumber_people["5"]=5;
ACnumber_people["6"]=6;
ACnumber_people["7"]=7;
ACnumber_people["8"]=8;
//Set up an associative array Workshop
//The keys represent the number of WS people
//The value represents thenumber of people
//We use this this array when the user set number of people from the form
var WSnumber_people= new Array();
WSnumber_people["None"]=0;
WSnumber_people["1"]=4;
WSnumber_people["2"]=4;
WSnumber_people["3"]=4;
WSnumber_people["4"]=4;
WSnumber_people["5"]=4;
WSnumber_people["6"]=5;
WSnumber_people["7"]=5;
WSnumber_people["8"]=5;
//Onsite course delivery
//getTrainerExp finds the trainer expenses based on a check box selection
function getOnsite()
{
var onsite="no";
//Get a reference to the form id="courseform"
var theForm = document.forms["courseform"];
//Get a reference to the checkbox id="includeexp"
var onSite = document.getElementById('onsite');
//If they checked the box set the course type value for Academy to 1.5
if(onSite.checked==true)
{
course_weight["AC"]=1.5;
}
//return the trainer expenses
return onsite;
}
// getCourseWeight() finds the course weight for integer based on the slection.
// take user's the selection from radio button selection
function getCourseWeight()
{
var courseweight=0;
//Get a reference to the form id="courseform"
var theForm = document.forms["courseform"];
//Get a reference to the typre the user Chooses name=selectedcoursetype":
var selectedCourseWeight = theForm.elements["selectedcoursetype"];
//Here since there are 4 radio buttons selectedCourseType.length = 4
//We loop through each radio buttons
for(var i = 0; i < selectedCourseWeight.length; i++)
{
//if the radio button is checked
if(selectedCourseWeight[i].checked)
{
//we set coursetype to the value of the selected radio button
//i.e. if the user choose the WS we set it to 1
//We get the selected Items value
//For example course_prices["WS".value]"
courseweight = course_weight[selectedCourseWeight[i].value];
//If we get a match then we break out of this loop
//No reason to continue if we get a match
break;
}
}
//We return the coursetype
return courseweight;
}
// getCourseType() finds the course type - AC or WS based on the selection.
// take user's the selection from radio button selection
function getCourseType()
{
var coursetype="none";
//Get a reference to the form id="courseform"
var theForm = document.forms["courseform"];
//Get a reference to the typre the user Chooses name=selectedcoursetype":
var selectedCourseType = theForm.elements["selectedcoursetype"];
//Here since there are 4 radio buttons selectedCourseType.length = 4
//We loop through each radio buttons
for(var i = 0; i < selectedCourseType.length; i++)
{
//if the radio button is checked
if(selectedCourseType[i].checked)
{
//we set coursetype to the value of the selected radio button
//i.e. if the user choose the WS we set it to 1
//We get the selected Items value
//For example course_prices["WS".value]"
coursetype = course_type[selectedCourseType[i].value];
//If we get a match then we break out of this loop
//No reason to continue if we get a match
break;
}
}
if
//We return the coursetype
return coursetype;
}
//This function finds the number of days based on the
//drop down selection
function getNumberDays()
{
var numberdays=0;
//Get a reference to the form id="courseform"
var theForm = document.forms["courseform"];
//Get a reference to the select id="days"
var selectedDays = theForm.elements["days"];
//set Days equal to value user chose
//For example number_days["Lemon".value] would be equal to 5
numberdays = number_days[selectedDays.value];
//finally we return numberdays
return numberdays;
}
//This function finds the number of AC people based on the
//drop down selection
function getACNumberPeople()
{
var ACnumberpeople=0;
//Get a reference to the form id="courseform"
var theForm = document.forms["courseform"];
//Get a reference to the select id="people"
var selectedPeople = theForm.elements["people"];
//set AC People equal to value user chose
//For example number_days["Lemon".value] would be equal to 5
ACnumberpeople = ACnumber_people[selectedPeople.value];
//finally we return numberdays
return ACnumberpeople;
}
//This function finds the number of WS people based on the
//drop down selection
function getWSNumberPeople()
{
var WSnumberpeople=0;
//Get a reference to the form id="courseform"
var theForm = document.forms["courseform"];
//Get a reference to the select id="people"
var selectedPeople = theForm.elements["people"];
//set WSPeople equal to value user chose
WSnumberpeople = WSnumber_people[selectedPeople.value];
//finally we return numberdays
return WSnumberpeople;
}
//getTrainerExp finds the trainer expenses based on a check box selection
function getTrainerExp()
{
var trainerexp="None";
//Get a reference to the form id="courseform"
var theForm = document.forms["courseform"];
//Get a reference to the checkbox id="includeexp"
var includeExp = document.getElementById('includeexp');
//If they checked the box set trainerexp to ACMEEXP
if(includeExp.checked==true)
{
trainerexp=" - ACM-EXP";
}
//return the trainer expenses
return trainerexp;
}
//getTrainerKit finds the kit shipping based on a check box selection
function getTrainerKit()
{
var trainerkit="None";
//Get a reference to the form id="courseform"
var theForm = document.forms["courseform"];
//Get a reference to the checkbox id="includekit"
var includeKit = document.getElementById('includekit');
//If they checked the box set trainerexp to ACMEEXP
if(includeKit.checked==true)
{
trainerkit=" ACM-SHP";
}
//return the trainer expenses
return trainerkit;
}
function calculateTotal()
{
//Here we get the total price by calling our function
//Each function returns a number so by calling them we add the values they return together
var pointstotal =
if (course_type = AC)
{
getCourseWeight() * getNumberDays() * getACNumberPeople()
}
else if (course_type = WS)
{
getCourseWeight() * getNumberDays() * getWSNumberPeople()
}
else
{
} ;
//display the result
var divobj = document.getElementById('totalPoints');
divobj.style.display='block';
divobj.innerHTML = "Points Total = " +pointstotal;
}
function calculateExp()
{
var expense = getTrainerExp() ;
var days = getNumberDays() ;
document.getElementById("trainerexp").innerHTML = "Please include Qty " +days +expense;
document.getElementById("trainertra").innerHTML = "Please include Qty 1 - ACM-TRA "
}
function calculateKit()
{
var kit = getTrainerKit() ;
document.getElementById("trainerkit").innerHTML = "Please include Qty 1 - " +kit;
}
function hideTotal()
{
var divobj = document.getElementById('totalPrice');
divobj.style.display='none';
}
function btns()
{
window.location.replace('http://btnsdownloads.co.uk/site/btns8/index08.html');
}
を*最小限のチェックアウト* – j08691
あなたはまた別に '場合(course_type = AC)' – j08691
での割り当てを持っている[MCVE]でlintエラーから 'if'文を右辺の式として使用しようとしていますか?私は 'var pointstotal = if(...){式}'が意味をなさないということです。スクリプトを実行するときにエラーが表示されるはずです。 – Teemu