I am trying to do an if statement to test whether the variable m is equal to game1 or game2 and if it is show it as a two move game and if its game3 or game4 show it as a one move game.

 game1 = Image[]game2 = Image[]game3 = Image[]game4 = Image[]

The above 4 variables are assigned to 4 different images.

 m := RandomChoice[{game1, game2, game3, game4}];If[m === game1 || game2 , InputString["This is a two move game"], InputString["This is a one move game"]] 

This is totally failing. the 4 game variables are assigned to images and we need to show the image and have a input box pop up

This is another alternative I came up with that also failed.

 m := RandomChoice[{game1, game2, game3, game4}];If[m == game1 || game2 , InputString["This is a two move game"]];If[m == game3 || game4 , InputString["This is a one move game"]]

Any help would be much appreciated.

2

Best Answer


You can't use this syntax: m === game1 || game2

For example instead of 1 == 2 || 3 you should use 1 == 2 || 1 == 3

However, you are using m multiple times, and each time it is used it will change. So you need to fix m, e.g.

m := RandomChoice[{game1, game2, game3, game4}];a = m;If[a == game1 || a == game2 , InputString["This is a two move game"]];If[a == game3 || a == game4 , InputString["This is a one move game"]]
moves01 = Thread[{game3, game4} -> "one move game"]moves02 = Thread[{game1, game2} -> "two move game"]moves = Association@Catenate[{moves01, moves02}]m := RandomChoice[{game1, game2, game3, game4}];moves[m]