Home > Web Front-end > JS Tutorial > body text

JavaScript Fun Question: Fragrance Vaporizer

黄舟
Release: 2017-02-04 15:47:46
Original
1190 people have browsed it

This topic is to test an evaporator filled with fragrance to see its service life.

We know the capacity content of the evaporator (calculated in ml), and the fragrance contained in it will evaporate a certain percentage every day (evap_per_day).

This evaporator requires at least threshold (percentage) of fragrance, otherwise it can no longer be used.

All numbers are positive.

How many days will it take for the evaporator to fail?

The function prototype is as follows:

function evaporator(content, evap_per_day, threshold)
Copy after login

The parameters are capacity, volatilization percentage, and minimum percentage.

For this question, it actually doesn’t matter whether the capacity is used or not. It can also be solved using only percentages, but I think capacity is better to understand.

The following is the solution to the capacity. It determines how much capacity remains after evaporation every day until the current capacity is less than the minimum limit capacity and returns the number of days.

function evaporator(content, evap_per_day, threshold){   
    var day = 0;  
    threshold = content * threshold / 100;  
    while(content >= threshold){  
        content *= (1 - evap_per_day / 100);  
        day++;  
    }  
    return day;  
}
Copy after login

The above is the content of JavaScript fun question: Fragrance evaporator. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!