Skip to content

Instantly share code, notes, and snippets.

@legarspol
Forked from 140bytes/LICENSE.txt
Created December 27, 2011 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save legarspol/1525413 to your computer and use it in GitHub Desktop.
Save legarspol/1525413 to your computer and use it in GitHub Desktop.
Plus or minus Game - 140byt.es

Plus or minus Game

Just a 84 Bytes Plus or minus Game.

Not sure it's the real english name of the game

Thanks to tsaniel for improvement.

How to use:

game("optional First text string");

How to play

Try to gess wich number your computer think about. If you're wrong he will give you clue to find the right number.

function(
b, //optional starting message
c // just to define the variable
){
for(
c = 0 | Math.random() * 100; // generate a random value between 0 and 100
b = c - ~ - prompt(b); // loop while c != value asked
b = b > 0 ? '+' : '-' // text prompted next turn
)
; // nothing in the loop
alert('win')
}
function(b,c){for(c=0|Math.random()*100;b=c-~-prompt(b);b=b>0?'+':'-');alert('win')}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "plusOrMinus",
"description": "The game of plus or minus.",
"keywords": [
"game",
"plus",
"minus"
]
}
<!DOCTYPE html>
<head>
<title> 140Byt.es Plus or Minus Sample</title>
</head>
<body>
<p>You should see a dialog Box</p>
<script>
var f = function(b,c){for(c=0|Math.random()*100;b=c-~-prompt(b);b=b>0?'+':'-');alert('win')}
f("Try a number");
</script>
</body>
</html>
@tsaniel
Copy link

tsaniel commented Dec 28, 2011

Save some bytes.

function(b,c){for(c=0|Math.random()*100;b=c-~-prompt(b);b=b>0?'+':'-');alert('win')}

@legarspol
Copy link
Author

Great !
Thanks for your help

@FarSeeing
Copy link

Save a few bytes with Date.now() technique taken from https://gist.github.com/1968854

`````` function(b,c){for(c=0|Date.now()%100;b=c-~-prompt(b);b=b>0?'+':'-');alert('win')}```

But for the first prompt undefined is shown, so function(b,c){for(c=0|Date.now()%100;b=c-~-prompt(b||'');b=b>0?'+':'-');alert('win')}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment