-2
我在這裏掙扎。我的JS在下面。 這裏的目標 - 用戶選擇課程類型 - WS或AC。 如果選中「現場」,則將AC值更新爲課程重量下的1.5。JS變量與IF ELSE
人數有不同的值,取決於是否選擇AC或WS。因此,在計算總計函數中有一個if語句,用於查看課程類型值 - AC或WS。
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');
}
時退房*在[MCVE]最小的* – j08691
您還可以在'如果(course_type = AC)' – j08691
除了賦值從lint錯誤中,你是否試圖使用'if'語句作爲右側表達式?我的意思是'var pointstotal = if(...){表達式}'沒有任何意義。運行腳本時它應該會引發錯誤。 – Teemu