181k views
1 vote
If totalMonths has a string value of "13", what does the code that follows display?var years = parseInt ( totalMonths / 12 );var months = totalMonths % 12;if ( years == 0 ) {alert ( months + " months.");} else if ( months == 0 ) {alert ( years + " years");} else {alert ( years + " years, and " + months + " months.");

}a) 1 years, and 1 monthsb) 1 year, and 1 monthc) 1 yearsd) 1 year

User HassenPy
by
5.3k points

1 Answer

3 votes

Answer:

The answer to this question is "Option a".

Explanation:

The description of the JavaScript code as follows:

  • In the code, there is two variable defined that are "years and months". The years convert string value in number and calculate years and holds value in years variable and months variable calculate the moths and holds value in months variable.
  • Then we use conditional statements in this statement we use two if blocks. In first if block we check that years variable value is equal to 0. if this condition is true. it will print months in the alert box.
  • In second if block we check that if months variable value is equal to 0. if this condition is true. it will print years in the alert box.
  • In else block, we use an alert box that prints years and months.

User JohnAllen
by
5.4k points