简体   繁体   中英

How can I see the output of a function in a console.log?

I've started study programming and I need some help with JS. I'd like to see at the console.log the result of a function that I've create. I'm using a educational platform that's gave me this exercises, and when I've made this they said me It's correct, but I want to see if the result by my own for understand how it works. in the bottom I'll give the question that they gave me.

 var carPlate= [
'RXB-2525', 'AKX-3333', 'ORO-7142','RXB-2525', 'AKX-3333', 'ORO-7142',
'AKX-3333', 'RXB-2525', 'AKX-3333','AKX-3333', 'RXB-2525', 'AKX-3333',   'RXB-2525', 'AKX-3333', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'AKX-3333', 'RXB-2525','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'ORO-7142', 'ORO-7142',
'ORO-7142', 'RXB-2525', 'AKX-3333','AKX-3333', 'ORO-7142', 'ORO-7142',
'AKX-3333', 'RXB-2525', 'AKX-3333','AKX-3333', 'RXB-2525', 'AKX-3333',
'RXB-2525', 'AKX-3333', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'AKX-3333', 'RXB-2525','AKX-3333', 'AKX-3333', 'RXB-2525']
      
    function calculateNumberEntries(carLicensePlate){
            for(i=0;i<carPLate.length;i++){
           return carPlate++
    }
   }
    function calculateValueDue(carLicensePlate){
        if(calculateNumberEntries(carLicensePlate)<21){
   return 
    }
   }
     //I've tried the solution below but doesn't works
    //console.log(calculateValueDue(carLicensePlate)+calculateNumberEntries(carLicensePlate))

"A car park wants to automate the collection of monthly payments. For this he decided to simplify the way of calculating the amount due by his client. The amount to be paid by its users depends on the number of entrances that the vehicle makes in the parking lot. At each entry, the vehicle license plate is registered. At the end of the month, the number of entries the vehicle made is counted and the following calculation is made:

If the driver has made up to 20 entries, he must pay R $ 10.00 per entry made. From the twenty-first entry onwards, each entry costs R $ 5.00 to the customer. Now, you should help automate billing by writing two functions.

The first function is called calculateInputNumber (plate). It must receive a single parameter that represents the license plate of a car. The function should return the number of entries that this car made in the parking lot. In other words, the number of times the plate passed as a parameter appears in the plates array.

The second function is called calculateDueValue (plate). It must receive a single parameter that represents the license plate of a car. The function must calculate the amount that the car owner has to pay according to the established pricing policy. Naturally, it will be necessary to use the first function within the second."

Sorry if gets to long this question, but I'm really appreciate that you read until the end. Thank you very much in advance.

Well the argument to the calculateValueDue function should be a specific car number plate. For example: AKX-3333 .

You should use the function name calculateInputNumber instead of calculateNumberEntries , since calculateInputNumber is the function name mentioned in the task description.

The calculateInputNumber function should have an if statement , that should check if the plate number given as function parameter, matches the loop entry. If it matches, then increase value of a variable by 1. The function should return the value of this variable.

The calculateValueDue function should call the calculateInputNumber function and use its return value, which is the number of times the plate number appears in the array.

The calculateValueDue function should then check this return value. If it is twenty or less, then multiple the value by 10 and return the value. If more than twenty, then subtract value from 20 and multiple by 5. Then add the result to 20*10, which is 200 and return the value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM