Why is my code not working? It seems perfectly fine to me...

var HowManyPikeMen=prompt("How many?")
squiffy.set("Cost", HowManyPikeMen*3);
if (Cost>Money) {
alert("You don't have enough money for that!") }
else {
squiffy.set("Pikemen", HowManyPikeMen) }

I can't see why it wont work. :|

  1. check indentation (4 spaces or a tab)
  2. check missing semicolons ;
  3. set("attribute", value) <=> get("attribute") vs. var attribute=value <=> attribute
    var Money=10;
    var HowManyPikeMen=prompt("How many?");
    set("Cost", HowManyPikeMen*3);
    if (get("Cost")>Money)                 // <-- get("Cost")
            alert("You don't have enough money for that!");
    else set("Pikemen", HowManyPikeMen);

Wow, thanks for spotting all those things for me. But sadly it still doesn't seem to work :/
It doesn't come up with an alert if it costs too much and it doesn't set the "Pikemen" variable to "HowManyPikeMen" if i have enough. I was wondering if I would be able to do this in the normal squiffy code instead (not JavaScript), would that be possible?

I fixed the previous javascript oriented codes above. (Try it again).
And I rewrited the codes with the minimum use of javascript as the following.

@set money=10
How many? {rotate HowMany:1:2:3:4:5} 

{if moneyLeft<0: You don't have enough money for that!}
{else:[[You hired {HowMany} pikemen.]](hirePikemen)}


Pikemen: {Pikemen}, Money: {money}

Log in to post a reply.