You will be writing a JavaScript program here using this evaluated solution. Ple
ID: 3668049 • Letter: Y
Question
You will be writing a JavaScript program here using this evaluated solution. Please be sure to incorporate the corrections identified by your instructor as you proceed to use the JavaScript programming language to code and test the problem using the repl.it programming tool for JavaScript.
Module main ()
//Declare local variables
Declare Real totalSales
Declare Real countyTax
Declare Real stateTax
Declare Real totalTax
//Function calls
Call inputData(totalSales)
Call calcCounty(totalSales, countyTax)
Call calcState(totalSales, stateTax)
Call calcTotal(countyTax, stateTax, totalTax)
Call printTax(countyTax, stateTax, totalTax)
End Module
//this module takes in the required user input from the user.
5.1 Module inputData(Real Ref totalSales)
5.1a Display “Enter the total sales for the month.”
5.1b Input totalSales
5.2 End Module
//this module calculates county tax.
//totalSales can be a value parameter because it is not changed in the module.
//countyTax must be a reference parameter because it is changed in the module
6.1 Module calcCounty(Real totalSales, Real Ref countyTax)
6.1a countyTax = totalSales * .02
6.2 End Module
//this module calculates state tax …
7.1 Module calcState(Real totalSales, real Ref stateTax)
7.1a stateTax = totalSales * .04
7.2 End Module
//this module calculates total tax …
8.1 Module calcTotal(Real Ref totalTax, Real stateTax, Real countyTax)
8.1a totalTax = countyTax + stateTax
8.2 End Module
//this module prints the total, county, and state tax …
9.1 Module printTax(Real countyTax, Real stateTax, Real Ref totalTax)
9.1a Display “The county tax is “, countyTax
9.1b Display “the state tax is “, stateTax
9.1c Display “The total tax is “, totalTax//
9.2 End Module
As is noted above, we will be using a tool called reptl.it to enter and test our JavaScript code snippets this week. It is recommended that you use the latest version of the Chrome browser for these labs. Please refer to last week’s homework assignment details if you have questions about how to maneuver in this tool.
Remember, your code should start with documentation and also comment certain sections or lines of your code as before. Document the first few lines of your program to include your name, the date, and a brief description of what the program does. You will need to create four (4) variables for this problem (totalSales, countyTax, stateTax, and totalTax). You will then need to create a function called inputData() that has no parameters and will return the total sales after prompting the user for this value. Don’t forget to convert this from a string to a number using the Number() function before returning it. The returned value will be set to the totalSales variable in the main part of the program. You will next create another function called calcCounty() that will pass in the totalSales value and will return the county tax, which will be set to the countyTax variable in the main part of the program. Likewise, a third function called calcState() will be created that will pass in the totalSales value and will return the state tax, which will be set to the stateTax variable in the main part of the program. Next, you will create another function called calcTotal() that will pass in the countyTax and stateTax values and will return the total tax, which will be set to the totalTax variable in the main part of the program. Last, you will create a function called printData() that will pass in the totalSales, countyTax, and stateTax and will print each out to the user using console.log(). The program will then end. Try it out using 1000 for the user entered total sales value … your results should be the following ..
Enter the total sales: 1000
The county tax is: 20
The state tax is: 40
The total tax is: 60
When your code is complete and runs properly, simply highlight all code that appears in the upper portion of the JS Playground window (the editor), then do a copy and paste here. Do the same for the output that appears on the bottom portion of the terminal or output screen.
Explanation / Answer
Hand trace of code
Statement #
1
totalSales
totalSales=0
2
countyTa
countyTax=0
3
stateTax
stateTax=0
4
totalTax
totalTax=0
5
inputData(totalSales)
5.1
inputData(ref 0)
5.1a
Enter the total sales for the month.
5.1b
totalSales=27097
5.2
End of inputData()
6
calcCounty(totalSales, countyTax)
totalSales=27097
countyTax=0
6.1
calcCounty(totalSales, ref countyTax=0)
totalSales=27097
countyTax=0
6.1a
countyTax = 27097 * .02
Calculate countyTax= 5419.4
totalSales=27097
countyTax=5419.4
6.2
End of calcCounty( ) method
7
calcState(totalSales, stateTax)
totalSales=27097
stateTax=0
7.1
calcState(totalSales, ref stateTax=0)
totalSales=27097
stateTax=0
7.1a
stateTax = 27097 * .04
Calculate stateTax= 1083.88
totalSales=27097
stateTax= 1083.88
7.2
End of calcState ()
8
calcTotal(countySales, stateTax, totalTax)
countySales=5419.4
salesTax=1083.88
totalTax=0
8.1
calcTotal(countySales=5419.4, stateTax=1083.88, totalTax=0)
countySales=5419.4
salesTax=1083.88
totalTax=0
8.1a
totalTax = 5419.3 + 1083.88
totalTax=6503.18
countySales=5419.4
salesTax=1083.88
totalTax=6503.18
8.2
End of calcTotal method
9
printTax(countyTax, stateTax, totalTax)
totalTax=6503.18
salesTax=1083.88
countySales=5419.4
9.1
printData(Real countyTax, Real stateTax, Real Ref totalTax)
totalTax=6503.18
salesTax=1083.88
countySales=5419.4
9.1a
The county tax is 5419.4
9.1b
the state tax is 1083.88
9.1c
The total tax is 6503.18
9.2
End of Module
Statement #
1
totalSales
totalSales=0
2
countyTa
countyTax=0
3
stateTax
stateTax=0
4
totalTax
totalTax=0
5
inputData(totalSales)
5.1
inputData(ref 0)
5.1a
Enter the total sales for the month.
5.1b
totalSales=27097
5.2
End of inputData()
6
calcCounty(totalSales, countyTax)
totalSales=27097
countyTax=0
6.1
calcCounty(totalSales, ref countyTax=0)
totalSales=27097
countyTax=0
6.1a
countyTax = 27097 * .02
Calculate countyTax= 5419.4
totalSales=27097
countyTax=5419.4
6.2
End of calcCounty( ) method
7
calcState(totalSales, stateTax)
totalSales=27097
stateTax=0
7.1
calcState(totalSales, ref stateTax=0)
totalSales=27097
stateTax=0
7.1a
stateTax = 27097 * .04
Calculate stateTax= 1083.88
totalSales=27097
stateTax= 1083.88
7.2
End of calcState ()
8
calcTotal(countySales, stateTax, totalTax)
countySales=5419.4
salesTax=1083.88
totalTax=0
8.1
calcTotal(countySales=5419.4, stateTax=1083.88, totalTax=0)
countySales=5419.4
salesTax=1083.88
totalTax=0
8.1a
totalTax = 5419.3 + 1083.88
totalTax=6503.18
countySales=5419.4
salesTax=1083.88
totalTax=6503.18
8.2
End of calcTotal method
9
printTax(countyTax, stateTax, totalTax)
totalTax=6503.18
salesTax=1083.88
countySales=5419.4
9.1
printData(Real countyTax, Real stateTax, Real Ref totalTax)
totalTax=6503.18
salesTax=1083.88
countySales=5419.4
9.1a
The county tax is 5419.4
9.1b
the state tax is 1083.88
9.1c
The total tax is 6503.18
9.2
End of Module
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.