What is the value of the variable named counter after the code that follows is executed? var percent = 0.54; var isValid = true; var counter = 1; if ((percent > 0.50) && (isValid == true)) { counter += 2; if (isValid == true) { counter++; } else if (percent >= 0.50) { counter += 3; } } else { counter++; }

Respuesta :

ijeggs

Answer:

The value of the variable counter after executing the given line of code is: 4

Explanation:

The Code snippet checks different values of the variable percent and isValid.

It checks these values at three stages

if ((percent > 0.50) && (isValid == true)) {

     This first check is true so it enters the inner loop

if (isValid == true)

       This condition is also true so at this point counter is assigned counter++

The third condition else if (percent >= 0.50) Also returns true so counter is assigned a new value counter += 3; (Which evaluates to 4). This is the final value of counter since the else condition is false.

ACCESS MORE