How to return result of function?

Javascript program not giving correct result?

  • Hey guys need help on my exam project please. My program needs to calculate nr off lessons user chooses from a radio button then multiply that by price of subject add 25% discount if user takes an online class and then add 15% vat to the final price. My code looks like this and works perfectly but when I try to add vat of 15% im not getting correct results?? var nr_lessons = new Array( ); nr_lessons["opt1"]=10; nr_lessons["opt2"]=20; nr_lessons["opt3"]=30; nr_lessons["opt4"]=40; var subject_prices= new Array( ); subject_prices["None"]=0; subject_prices["Maths"]=250; subject_prices["Science"]=200; subject_prices["IT"]=175; subject_prices["Programming"]=220; // getNrOfLessons( ) finds the price based on the number of lessons selected. function getNrOfLessons( ) { var nrOfLessons=0; var theForm = document.forms["lessonPrice"]; var selectedplan = theForm.elements["priceplan"]; //loop through each radio buttons for(var i = 0; i < selectedplan.length; i++) { //if the radio button is checked if(selectedplan[i].checked) { //set the number of lessons to the value of the selected radio button nrOfLessons = nr_lessons[selectedplan[i].value]; break; } } //We return the number of lessons return nrOfLessons; } //This function finds the subject price based on the drop down selection chosen function getSubjectPrice() { var SubjectPrice=0; var theForm = document.forms["lessonPrice"]; var selectedSubject = theForm.elements["subject"]; //set subject Price equal to value user chooses SubjectPrice = subject_prices[selectedSubject.value]; //return subject price return SubjectPrice; } //onlineClass() Determines if the user wants to take an online class based on a check box selection function onlinePrice() { var onlineprice=0; var theForm = document.forms["lessonPrice"]; var takeOnlineClass = theForm.elements["onlineclass"]; //If they checked the box set 25% discount on price for online class if(takeOnlineClass.checked==true) { onlineprice=(getNrOfLessons()*getSubject… } //return price for online class return onlineprice; } function incentreClass() { var incentreClass=0; var theForm = document.forms["lessonPrice"]; var takeHomeClass = theForm.elements["homeclass"]; //If user checked the box multiply number of lessons with subject price if(takeHomeClass.checked==true){ homeClass=(getNrOfLessons()*getSubjectPr… } //return incentre class price return incentreClass; } function calculateTotal() { //calculate vat@ 15% by calling functions var vat = (getNrOfLessons() * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) *0.15; //calculate total price by calling functions and adding the vat @ 15% var price = (getNrOfLessons() * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) + vat; //display the result var divobj = document.getElementById('totalPrice'); divobj.style.display='block'; divobj.innerHTML = "Total Price For your studies (inc Vat @ 15%) R"+price; } </script>

  • Answer:

    Just type in: var nr_lessons = new Array( ); nr_lessons["opt1"]=10; 'bdjnonjdvjsdvlnv onjdvjsdvlnv ///////////[[[]]]]1892874765y //calculate vat@ 15% by calling functions var vat = (getNrOfLessons() * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) *0.15; //calculate total price by calling functions and adding the vat @ 15% var price = (getNrOfLessojbhdcklvnjdpIOSHJCIPHP'IOGF… * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) + vat; getNrOfLessons( ) finds the price based on the number of lessons selected. function getNrOfLessons( ) { var nrOfLessons=0; var nr_lessons = new Array( ); nr_lessons["opt1"]=10; nr_lessons["opt2"//calculate total price by calling functions and adding the vat @ 15% var price = (getNrOfLessojbhdcklvnjdpIOSHJCIPHP'IOGF… * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) + vat; getNrOfLessons( ) finds the price based on the number of lessons selected. function getNrOfLessons( ) { var nrOfLessons=0; var nr_lessons = new Array( ); nr_lessons["opt1"]=10; nr_lessons["opt2"]=20; nr_lessons["opt3"]=30; nr_lessons["opt4"]=40; dcjfnsnvosfjdnvjofdnbvdflbdfjn'bdjnonjd… ///////////[[[]]]]1892874765y nr_lessons["opt1"]=10; nr_lessons["opt2"]=20; nr_lessons["opt3"]=30; nr_lessons["opt4"]=40; dcjfnsnvosfjdnvjofdnbvdflbdfjn'bdjnonjd… ///////////[[[]]]]1892874765y //calculate vat@ 15% by calling functions var vat = (getNrOfLessons() * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) *0.15; //calculate total price by calling functions and adding the vat @ 15% var price = (getNrOfLessojbhdcklvnjdpIOSHJCIPHP'IOGF… * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) + vat; getNrOfLessons( ) finds the price based on the number of lessons selected. function getNrOfLessons( ) { var nrOfLessons=0; var nr_lessons = new Array( ); nr_lessons["opt1"]=10; nr_lessons["opt2"]=20; nr_lessons["opt3"]=30; nr_lessons["opt4"]=40; dcjfnsnvosfjdnvjofdnbvdflbdfjn'bdjnonjd… ///////////[[[]]]]1892874765y nr_lessons["opt1"]=10; nr_lessons["opt2"]=20; nr_lessons["opt3"]=30; nr_lessons["opt4"]=40; dcjfnsnvosfjdnvjofdnbvdflbdfjn'bdjnonjd… ///////////[[[]]]]1892874765y //calculate vat@ 15% by calling functions var vat = (getNrOfLessons() * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) *0.15; //calculate total price by calling functions and adding the vat @ 15% var price = (getNrOfLessojbhdcklvnjdpIOSHJCIPHP'IOGF… * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) + vat; getNrOfLessons( ) finds the price based on the number of lessons selected. function getNrOfLessons( ) { var nrOfLessons=0; var nr_lessons = new Array( ); nr_lessons["opt1"]=10; nr_lessons["opt2"]=20; nr_lessons["opt3"]=30; nr_lessons["opt4"]=40; dcjfnsnvosfjdnvjofdnbvdflbdfjn'bdjnonjd… ///////////[[[]]]]1892874765y nr_lessons["opt1"]=10; nr_lessons["opt2"]=20; nr_lessons["opt3"]=30; nr_lessons["opt4"]=40; dcjfnsnvosfjdnvjofdnbvdflbdfjn'bdjnonjd… ///////////[[[]]]]1892874765y //calculate vat@ 15% by calling functions var vat = (getNrOfLessons() * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) *0.15; //calculate total price by calling functions and adding the vat @ 15% var price = (getNrOfLessojbhdcklvnjdpIOSHJCIPHP'IOGF… * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) + vat; getNrOfLessons( ) finds the price based on the number of lessons selected. function getNrOfLessons( ) { var nrOfLessons=0; var nr_lessons = new Array( ); nr_lessons["opt1"]=10; nr_lessons["opt2"]=20; nr_lessons["opt3"]=30; nr_lessons["opt4"]=40; dcjfnsnvosfjdnvjofdnbvdflbdfjn'bdjnonjd… ///////////[[[]]]]1892874765y nr_lessons["opt1"]=10; nr_lessons["opt2"]=20; nr_lessons["opt3"]=30; nr_lessons["opt4"]=40; dcjfnsnvosfjdnvjofdnbvdflbdfjn'bdjnonjd… ///////////[[[]]]]1892874765y //calculate vat@ 15% by calling functions var vat = (getNrOfLessons() * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) *0.15; //calculate total price by calling functions and adding the vat @ 15% var price = (getNrOfLessojbhdcklvnjdpIOSHJCIPHP'IOGF… * getSubjectPrice()) - (onlinePrice()) - (incentreClass()) + vat; getNrOfLessons( ) finds the price based on the number of lessons selected. function getNrOfLessons( ) { var nrOfLessons=0; var theForm = document.forms["lessonPrice"]; var selectedplan = theForm.elements["priceplan"];PIDJSFIJHR… /////////47474747473 oij

Timothy C at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.