so I'm really new and bad at JavaScript and for an assignment at course I have to create a web application thing that works like a trip calculator on vehicle hire websites. So it's meant to take what the user inputs and returns a quote based on that. - I've had a lot of help from my tutor and other class members but we have just started the weekend and it's due on Sunday night and I'm freaking out because i have no idea how to finish it.
What I am trying to do at the moment is get it print a quote based on a calculation that is based on how many KM's they'll travel per day and what type of vehicle they have chosen. At my current state this is my code:
I have created a JS Fiddle with the project here: https://jsfiddle.net/myLoucfd/
My current problem is that I am getting this error: https://i.stack.imgur.com/5bUP6.png
From my understanding it has something to do with the code in here:
function displayVehicles(vehicles) {
var s = '';
$.each(vehicles, function (i, vehicle) {
s = s + getHTMLVehicleItem(vehicle);
});
//Set inner HTML if Vehicles list container with items
vehicleListEl.html(s); // populating the wrapper
vehicleButtons = $('.vehicle-button');
$.each(vehicleButtons, function (i, vehicleButton) {
$(this).on('click', function () {
var selectedVehicleId = $(this).data('id');
var vehicle = getVehicleByID(selectedVehicleId);
var vehicleInfoHTML = getHTMLVehicleInfo(vehicle);
$("#detail-wrapper-" + vehicle.id).html(vehicleInfoHTML);
$('.quoteButton-' + vehicle.id).on("click", function(){
displayQuote(vehicle);
});
var wrapper = $("#detail-wrapper-" + vehicle.id);
$("#detail-wrapper-" + vehicle.id).show();
console.log();
// use jquery to find the wrapper div - have the vehicle object can use as the ID.
$("#hide-" + vehicle.id).click(function () {
$("#detail-wrapper-" + vehicle.id).hide();
});
// selectedVehicle = findVehicleByName(vehicleArray, selectedVehicleName);
});
});
// //Target the Vehicles
// var vehicles = $('.vehicle-list--item');
// //Loop through and add click event Listeners
// $.each(vehicles, function (i, vehicle) {
// $(this).on('click', function () {
// displayVehicles($(this));
// });
// });
}
and it seems to be effecting this:
function getHTMLVehicleInfo(vehicle) {
return `<div class="expanded-info">
<div></div>
<div>
<ul>
<li>${vehicle.engineSize}</li>
<li>${vehicle.driveType}</li>
<li>${vehicle.fuelTank}</li>
<li>${vehicle.transmissionType}</li>
<li>${vehicle.multiMedia}</li>
<li>${vehicle.safetyFeatures}</li>
<li>${vehicle.reversingCamera}</li>
<button class="quoteButton-${vehicle.id}">Get Quote</button>
<div id="displayedQuote-${vehicle.id}"></div>
</ul>
</div>
</div>`;
}
The code is meant to show a list of vehicles you can hire and show you details about them, then let you choose to get a quote which is what I am working on now but the quote needs to calculate based on; how far they are travelling per day, how many people there are and what type of car they have. So at the moment it can search and display the results, however now that I am trying to add the form that lets you input how far you are travelling per day and then submit and get a quote it's breaking and I generally have no clue how to do it.
Any help at all would be greatly appreciated!
Thanks, Dan / A hopeless student