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

Tidal
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) }

Tidal

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


story10
  1. check indentation (4 spaces or a tab)
  2. check missing semicolons ;
  3. set("attribute", value) <=> get("attribute") vs. var attribute=value <=> attribute
[[start]]:
    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);

Tidal

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?


story10

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.

[[start]]:
@set money=10
How many? {rotate HowMany:1:2:3:4:5} 
+++Done
        set("moneyLeft",get("money")-3*get("HowMany"));

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

[[hirePikemen]]:
        set("Pikemen",get("HowMany"));
        set("money",get("moneyLeft"));

Pikemen: {Pikemen}, Money: {money}

Log in to post a reply.

Support

Forums