Ask Question
15 March, 22:26

Rainfall_mi is a string that contains the average number of inches of rainfall in Michigan for every month (in inches) with every month separated by a comma. Write code to compute the number of months that have more than 3 inches of rainfall. Store the result in the variable num_rainy_months. In other words, count the number of items with values > 3.0.

+5
Answers (1)
  1. 15 March, 23:51
    0
    Hi!

    The answer in jа vascript is:

    function monthsWithMoreOfThree () {

    var Rainfall_mi = '3,4,1,5,2,6,7,9'; / /Defined and declared

    var num_rainy_months = 0;

    var values = Rainfall_mi. split (","); / /use split method for Strings. Array is returned

    for (var i = 0; i < values. length; i++) { / /for each value, compares with 3

    if (values[i] > 3) { / /In jа vascript, you can compare an String value with an int. Can use parseInt (aString) to explicit parse but is not necessary

    num_rainy_months++; / /If value is greater than 3, adds 1 to num_rainy_months

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Rainfall_mi is a string that contains the average number of inches of rainfall in Michigan for every month (in inches) with every month ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers