Question
IN JAVASCRIPT Calculate Profit Description You are required to calculate the profit percentage. The profit percentage is calculated as follows: (sellingPrice - costPrice)*100 / costPrice
IN JAVASCRIPT
Calculate Profit
Description
You are required to calculate the profit percentage. The profit percentage is calculated as follows:
(sellingPrice - costPrice)*100 / costPrice
Input Description: The first line of input consists of the cost price. The second line of input consists of the selling price. Input(s) have already been taken care of in the code. Output Description: The first line of output should consist of the profit percentage. Sample Input 1:
100 132
Sample Output 1:
32
Explanation 1: The profit percentage is calculated as follows: (132-100)*100/100 = 32. Sample Input 2:
150 165
Sample Output 2:
10
Explanation 2: The profit percentage is calculated as follows: (165-150)*100/150 = 10.
Note: 1. Follow all TODOs given in the stub code. 2. Do NOT edit the stub code given to you. Write all your code within the space allocated and marked using comments - BEGIN and END. 3. Follow the exact same format of the output, as shown above.
EDIT THE BELOW CODE
process.stdin.on('data', function(chunk) { let lines = chunk.toString().split(' '); let costPrice = parseInt(lines[0]); let sellingPrice = parseInt(lines[1]); // BEGIN: Write all your code below this line // TODO 1: Write a function "calculateProfit" to calculate the profit in %. /** * Function to calculate profit percentage * @param {Number} costPrice - cost price of an item * @param {Number} sellingPrice - selling price of an item * @returns {Number} - the calculated profit (in percentage) */
// TODO 2: Now you modify the code written above so that the function is exported. /** * Don't write any module.exports statement explicitly. */ // END: Write all your code above this line console.log(module.exports.calculateProfit(costPrice, sellingPrice)); })
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started