-1

I need to build a kind of "game" for my home work the mission is to give the first player to choose a number and the second player need to guesses the number . there is one problem that when the first player typing the number it is reveal to the second user so my question is how to make a asterisk that the other player will not see the data(this is the main mission on this exercise)?

this is my code

<html>
<head>
<script type="text/javascript">
    var num1 = parseInt(prompt('Enter your number.'));
    var num2 = parseInt(prompt('try gusses the number'));
    var theBiggerNumber = (num1==num2)?alert('you win'):alert('you lost');
</script>
</head>
</html>
darkwings
  • 17
  • 5
  • Probably a duplicate of http://stackoverflow.com/questions/4508077/placing-an-input-of-type-password-in-prompt-box – Gil May 05 '14 at 08:32
  • you can't change the look of `prompt()`, you'll need to create a different place for player 1 to type, such as `` – kennypu May 05 '14 at 08:32
  • always use === instead of == ([more info](http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons)) – Igor Milla May 05 '14 at 08:52
  • Look at the solution of your homework below in answer...would that suffice? – Slaven Tomac May 05 '14 at 09:24

1 Answers1

0

Prompt is always used for reading user inputs...

http://www.w3schools.com/jsref/met_win_prompt.asp

You can't use it for some custom data type (in this case password). Consider implementing in with html and js:

http://jsfiddle.net/Bb3sS/

HTML:

Player 1<input id='1' type='password'></input><br/>
Player 2<input id='2' type='password'></input><br/>
<button onclick='whoWon()'>Who won</button>

JS:

whoWon = function () {
    var num1 = parseInt(document.getElementById('1').value);
    var num2 = parseInt(document.getElementById('2').value);

    (num1==num2)?alert('you win'):alert('you lost');
}
Slaven Tomac
  • 1,552
  • 2
  • 26
  • 38