Why is my code not working? It seems perfectly fine to me...
Tidal
11 May 2017, 22:16var 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
11 May 2017, 22:16I can't see why it wont work. :|
story10
11 May 2017, 22:25- check indentation (4 spaces or a tab)
- check missing semicolons ;
- 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
12 May 2017, 04:00Wow, 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
12 May 2017, 13:29I 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}