jeudi 21 mai 2020

why my code doesnt run right? whats the promble of this if statment?

iam desiging a web site that can change the prices when for first time i click on slider the price become 19.99 and for the next time my price become 199.99. my project is this https://www.frontendmentor.io/challenges/pricing-component-with-toggle-8vPwRMIC

im using a variable if the variable ==1 then change the price to 199.99 and when the variable ==2 then change price to 19.99 ; but every time i click the price stays on 19.99:/

$(function(){
    var m = 1;
    $(".switch").click(function(){
        if(prices == 1){
            alert("hi");
        $("#h1").html("$199.99");
        $("#h2").html("$249.99");
        $("#h3").html("$399.99");
            m = 0;
        } else{
            alert("bye");
            $("#h1").html("$19.99");
        $("#h2").html("$24.99");
        $("#h3").html("$39.99");
            m = 0;
        }
        
    });
    
});

when i click both hi and bye alerts ,alerted and i dont know why ???:/// the return statment in if block also doesn't the solution, i tried.




Aucun commentaire:

Enregistrer un commentaire