Help a JS virgin find that sweet spot
Name:
Anonymous
2012-11-13 1:47
I'm practicing JS by trying to make a rock, paper, scissor game.
I have failed.
Can /prog/ help a nigga out?
http://pastebin.com/2Sq06a0c
Everything is appreciated, just keep in mind I'm new as fuck to programming.
Name:
Anonymous
2012-11-13 2:08
Not bad considering. I don't see where you have failed.
Name:
Anonymous
2012-11-13 2:10
I don't see where either, but it doesn't run.
Name:
!3fTMfZ5W2s
2012-11-13 7:58
jjjjj
Name:
Anonymous
2012-11-13 10:00
Welcome to Javascript, where the syntax is shit and nothing ever works.
Enjoy your stay
Name:
Anonymous
2012-11-13 10:36
This is why you get for using such a shit language.
Name:
Anonymous
2012-11-13 10:54
I am pretty sure there's a } missing
Name:
Anonymous
2012-11-13 10:55
prompt() returns a string
player1 + player2 === "12" // true
player1 + player2 === 3 //nope
ihbt
Name:
Anonymous
2012-11-13 11:43
>>8
The wonders of dynamic typing!
Name:
Anonymous
2012-11-13 11:50
>>8,9
So PHP would have gotten this right?
Score one more for PHP!
Name:
Anonymous
2012-11-13 12:25
>>9
The ``wonders of dynamic typing'' brought to you by the language with the second-worst coercion rules, that is.
Name:
Anonymous
2012-11-13 13:44
/polecat kebabs/
Name:
Anonymous
2012-11-13 14:27
Where's the Javashit troll?
Is
>>1-san the Javashit troll?
Name:
Anonymous
2012-11-13 17:43
>>11
Second only to
yeah there you are!
Name:
Anonymous
2012-11-14 0:48
var choice = ['rock', 'scissor', 'paper'],
player = choice.indexOf(prompt('choose rock paper scissor')),
computer = ~~ (Math.random() * 3);
if (player === -1) throw new Error('fuck you niggar !!');
console.log(
choice[player] + ' vs ' + choice[computer] + ': You ',
Math.abs(computer - player) === choice.length -1 ? 'lose' : //roll over
player === computer ? 'tie' :
player < computer ?
'win' :
'lose'
);
//god language
Name:
Anonymous
2012-11-14 0:55
>>15
doesn't work. player = paper, computer = rock.
Name:
Anonymous
2012-11-14 1:55
remove the math.abs on line 9
dunno why I put that there
Name:
Anonymous
2012-11-14 3:28
var choices = {"rock" : 1, "paper" : 4, "scissors": 3};
var choicesBackward = {1 : "rock", 4 : "paper", 3 : "scissors"};
var choicesArray = ["rock", "paper", "scissors"];
function player(name, playFunction) {
this.choice = 0;
this.name = name;
this.winCount = 0;
this.play = playFunction;
};
function getWinner(player1, player2) {
var result;
result = player1.choice - player2.choice;
if(player1.choice == player2.choice)
return "tie";
if(result == -2 || result == 3 || result == -1)
{
player1.winCount += 1;
return player1;
}
else
{
player2.winCount += 1;
return player2;
}
}
function playAndGetResults(player1, player2) {
var result;
player1.choice = player1.play();
player2.choice = player2.play();
console.log(player1.name + " chose " + choicesBackward[player1.choice]);
console.log(player2.name + " chose " + choicesBackward[player2.choice]);
result = getWinner(player1, player2);
if(result == "tie")
console.log("tie");
else
console.log("player " + result.name + " won with " + choicesBackward[result.choice]);
}
function botSelectChoice() {
var choicesArrayIndex;
choicesArrayIndex = Math.floor(Math.random() * 10 % 3);
return choices[choicesArray[choicesArrayIndex]];
}
function main() {
var player1 = new player("Alice", botSelectChoice);
var player2 = new player("Bob", botSelectChoice);
playAndGetResults(player1, player2);
}
paste it into your interpreter, and just call main() over and over
Name:
Anonymous
2012-11-14 6:26
>>15
===
~~
typical javashit
Name:
Anonymous
2012-11-14 8:22
>>18
var choicesBackward
Leah quality
!
Name:
Anonymous
2012-11-14 12:08
let v = ['rock' 'paper' 'scissors' 'rock']
let p1 = input()
let p2 = input()
if p1 = p2
print('Tie.')
else
let winner,loser,n = {
if v[v.indexof(p2)+1] = p1
(p1,p2,1)
else
(p2,p1,2)
}
print('$winner beats $loser. Player $n wins.')