Danienllxxox
Danienllxxox

Reputation: 423

JQuery variable if statement error

I am trying to check whether the content that a user has submitted contains the correct information. I am doing this by adding the inputted context to a variable [code] and then trying an if else catch to see whether it matches what I want. [strong] variable.

However, it does not appear to be working, can anyone shed some light on this? Please see the below code.

$(document).ready(function() {

    $('#button-bold').click(function() {  
        var code = jQuery("textarea#bold-code").val();

        var $pass = "Congratulations, You have entered this correctly";
        var $fail = "Oops, Look again, can you see where you have gone wrong?"

        var $strong = "<strong>Recreate this preview Exactly</strong>"; 

        if (code == strong) {
            alert(pass);
            $('#bold-output').append(code)

        }else {
            alert(fail);
        }
});
});

Thank you all in advance.

Upvotes: 0

Views: 374

Answers (1)

Rup
Rup

Reputation: 34408

You've got mismatched variable names with and without dollars - you're defining $strong, $pass and $fail with leading dollars but using strong, pass and fail without the dollar.

(As an aside, where you see the dollar prefix on JavaScript variables it usually means that they contain jQuery selectors, e.g.

var $output = $('#bold-output');

rather than general data - but that's just one convention.)

Upvotes: 1

Related Questions