Simple equation on Javascript not working and I can't see the problem

I’m trying to solve a simple equation "2^x=y" in javascript, but I can’t see what’s wrong with it, the browser just seems to enter an infinite loop… Here’s the code:

Edit: I changed the code to the whole script so you guys can see, the function that does the equation is the last one. Also apparently I have to talk more in order to edit the post sorry 🙂

var x = 0;
var y = 0;

function SolveEquation(input){
    while(x < input){
        x = Math.pow(2, y);
        y = y+1;
    }
    if(x >= input){
        return x;
    }
}

25 thoughts on “Simple equation on Javascript not working and I can't see the problem”

Leave a Comment