Question: I did the work below for javascript file for webpage. The change model button and change duration button are not working. please let me know
I did the work below for javascript file for webpage. The change model button and change duration button are not working. please let me know why thank you
The instructions describe the missing logic that is needed; you will translate these into JavaScript in the places indicated.
You are encouraged to use the provided naming convention for ease of review.
create variables
create variables to hold the values for modelName and duration
INSERT YOUR CODE HERE
let modelName XYZ;
let modelDuration ;
helper function
create a function called recalculate which will
create a variable to represent the calculatedcost span element. That will look something like:
let costLabel document.getElementByIdcalculatedcost;
check the value of the modelName variable, and use that to calculate the new total cost:
eg if modelName is currently XYZ duration gives us the new total cost.
if modelName is currently CPRG duration gives us the new total cost.
set the value of the calculatedcost element's innerHTML to this new value
INSERT YOUR CODE HERE
function recalculate
let costLabel document.getElementByIdcalculatedcost;
if modelName XYZ
let totalCost modelDuration ;
costLabelinnerHTML totalCost;
else if modelName CPRG
let totalCost modelDuration ;
costLabelinnerHTML totalCost;
model button logic
first, create a variable to represent the "Switch Model" pseudobutton hint: can use getElementById
second, create a function called changeModel which checks the value of the model name variable. This function will:
create a variable to represent the modeltext span element
if modelName is currently XYZ change the value of modelName to CPRG and change the innerHTML of the modeltext span element to "Model CPRG
if modelName is currently CPRG change the value of modelName to XYZ and change the innerHTML of the modeltext span element to "Model XYZ
then, recalculate the total cost.
finally, uncomment the following line of JavaScript to have this function run automatically whenever the pseudobutton is clicked:
modelButton.addEventListenerclick changeModel;
INSERT YOUR CODE HERE
let modelButton document.getElementByIdmodelButton;
function changeModel
let modelText document.getElementByIdmodeltext";
if modelName XYZ
modelName CPRG;
modelText.innerHTML "Model CPRG;
else if modelName CPRG
modelName XYZ;
modelText.innerHTML "Model XYZ;
recalculate;
modelButton.addEventListenerclick changeModel;
duration button logic
first, create a variable to represent the "Change Duration" pseudobutton.
then, create a function called changeDuration that will
create a variable to represent the durationtext span element
prompt the user for a new duration
save the result of the prompt to the duration variable
change the innerHTML of the durationtext span element to this new value
recalculate the total cost
finally, attach this function to the "Change Duration" pseudobutton, so it runs whenever the button is clicked.
INSERT YOUR CODE HERE
let durationButton document.getElementByIddurationButton;
function changeDuration
let durationText document.getElementByIddurationtext";
var newDuration document.getElementByIddurationInputvalue;
if newDuration null
var duration newDuration;
durationText.innerHTML duration;
recalculate;
durationButton.addEventListenerclick changeDuration;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
