How can I equal random function and input value?
My code :
Html
jQuery
function Random() {
var length = 6,
charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
retVal = "";
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
}
var ctx = document.getElementById("random").getContext('2d');
ctx.font = "50px Arial";
ctx.fillText(Random(), 0, 40);
$("#random").click(function () {
if($("#rand").val() !== Random()){
ctx.clearRect ( 0,0,1000,1000 );
ctx.fillText(Random(), 0, 40);
}
});
$('#rand').bind('keypress keyup change', function () {
if ($(this).val() !== Random()) {
$(this).addClass('false').removeClass('true').attr('data-filter', 'false'), $("#" + this.id + "s").css({
"color": "#C41111"
}).text("Characters in conflict with each other!");
} else {
$(this).addClass('true').removeClass('false').attr('data-filter', 'true'), $("#" + this.id + "s").css({
"color": "#7FAC25"
}).text($(this).val() + " is accepted!");
}
});
I want equal this if($("#rand").val() !== Random()) but i can't ?