javascript check if function parameter meets a condition -



javascript check if function parameter meets a condition -

i'm trying write basic "quest" function , have run few issues. this i've done far

js var clicks = 0; var coins = 10; var quests = function(type, required, reward, message) { this.type = type; this.required = required; this.reward = reward; this.message = message; this.quest = function() { if (this.type >= this.required) { coins += this.reward; homecoming this.message; } else { alert('you don\'t have plenty ' + required); } }; }; quest1 = new quests(clicks, 10, 50, 'you completed quest!'); quest2 = new quests(clicks, 5, 50, 'you completed quest!'); thequests = [quest1, quest2]; $(document).ready(function() { $('#click').click(function() { clicks += 1; $('#queststuff').text(clicks); }); $('#quest').click(function() { $('#queststuff').html(quests[math.floor(math.random() * 2)].quest()); }); }); html <button id="quest">quest</button> <button id="click">click me!</button> <div id="queststuff"> </div>

eventually i'll using other clicks, wanted basic function working. i'm new functions, @ moment when clicking 'quest' nil happens, while i'm wanting alert display. i've gone wrong somewhere in code. able point me in right direction?

you assigning clicks, immutable number, this.type. value 0 initially, , this.type stays 0 after assignment. should compare clicks this.required within quest method.

here's jsfiddle fork version using data-attributes

javascript

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -