Ask Question
22 July, 15:44

function calculate () { var s = 2; var x = 2; var y = 3; if (x > 4) { s=s + 2; } else if (y > 4) { s=s + 4; } else { s+=3; } alert ("s="+s); }//close function

+2
Answers (1)
  1. 22 July, 16:10
    0
    The output of the given jа vascript code is "5".

    Explanation:

    In the given jа vascript code, a method calculate is declared, inside the method, three variable "s, x, and y" is declared, in which all variable assigns a value, that is "2, 2, and 3". In the next step, a conditional statement is defined, that check value, which can be described as follows:

    In the, If the block, x variable checks its value is greater then 4 if it is true, it will add value 2 in s variable otherwise, it will go to else if block. In this block it will check the value of y variable greater then 4 if it is true, it will add value 4 in s variable. In both of the above conditions is false, it will go to else section, in this, variable "s" add value 3 in its variable, and use an alert box to print its value.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “function calculate () { var s = 2; var x = 2; var y = 3; if (x > 4) { s=s + 2; } else if (y > 4) { s=s + 4; } else { s+=3; } alert ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers