JavaScript - How Can I Remove String From My Rock, Paper Scissor Java Game?
First of all, I wanna make my code using (while loop, do while loop, int, double, if, else, else if, Math.random, Scanner-- not string or boolean).
-Actually the game goes like, after the user and the computer has has selections it is gonna be displayed and then tell who wins and who does not--I dont know how to do it. - When user presses 4, the the computer tells wins, loses and ties. This happens to me after two tries, wheteher i press 4 or not.(actully its |y/n| in mine and i want to change it to just 4 to quit). -The user is only allowed numbers from 1 to 4, but apparently, i add any number and it works. -My code gos like this: import java.util.Scanner; import java.util.Random; public class boobitty { public static void main (String[] args) { int Computer=0,Player=0,tie=0,compic,pscore; String str="y"; Random generate= new Random(); Scanner scan=new Scanner(System.in); while (str.equals("y")) { compic=generate.nextInt(3)+1; System.out.println ("Enter 1 for Rock, 2 for Paper, and 3 for Scissors"); pscore=scan.nextInt(); if (compic==pscore) { System.out.println("Tie Game"); tie++; } else { switch (pscore) { case 1: { if (compic==2) { System.out.println ("Paper beats Rock"); System.out.println ("Computer wins"); Computer++; } else { System.out.println ("Rock beats Scissors"); System.out.println ("Player wins!"); Player++; } break; } case 2: { if (compic==1) { System.out.println ("Paper beats Rock"); System.out.println ("Player wins!"); Player++; } else { System.out.println ("Scissors beat Paper"); System.out.println ("Computer wins!"); Computer++; } break; } case 3: { if (compic==1) { System.out.println ("Rock beats Scissors"); System.out.println ("Computer wins"); Computer++; } else { System.out.println ("Scissors beat Paper"); System.out.println ("Player wins"); Player++; } break; } default: { System.out.println("Enter 1 2 or 3"); break; } } } Scanner scen = new Scanner (System.in); System.out.println ("Play again? y/n"); str = scen.nextLine(); if(!(str.equals("y"))) { System.out.println ("Scores:"); System.out.println ("Ties= "+tie+" Wins= "+Player+" Losses= "+Computer); } else { System.out.println ("playing again"); } } } } Similar TutorialsOkay I'm writing a JavaScript application that would prompt the user for a number between 0 and 2, generate a random number for the computer, then take that input and display two images (in this case two hands making rock, paper, or scissor symbols at each other) using an array, and displaying text indicating a win, draw, or loss. I'm having a lot of problems getting this to work as I am new to JavaScript and am wondering if anyone could help me fix this problem. I just want the input from the prompt AND the random number to translate to what in the array should be displayed and what text is then shown at the bottom. Any comments/advice/help is greatly appreciated! By the way for some reason it doesn't let the letters H T M L show up together so that is where the ellipses are showing up! Code: <script type = "text/javascript"> selection = prompt("Enter 0 for rock, 1 for paper, and 2 for scissors") userChoice = parseInt(selection) arrayHolder = new Array(); arrayHolder[0] = "rock.jpg"; arrayHolder[1] = "paper.jpg"; arrayHolder[2] = "scissors.jpg"; compchoice = Math.floor(Math.random()*arrayHolder.length) function playGame(idholder1) { document.images["userpic"].src = arrayHolder[userchoice]; document.images["comppic"].src = arrayHolder[compchoice]; if (userChoice == 0 && compchoice == 0) { document.getElementbyId(idholder1).innerHTML = "DRAW!" } else if (userChoice == 0 && compchoice == 1) { document.getElementbyId(idholder1).innerHTML = "Paper beats Rock, you lose!" } else if (userChoice == 0 && compchoice == 2) { document.getElementbyId(idholder1).innerHTML = "Rock beats Scissors, you win!" } else if (userChoice == 1 && compchoice == 0) { document.getElementbyId(idholder1).innerHTML = "Paper beats Rock, you win!" } else if (userChoice == 1 && compchoice == 1) { document.getElementbyId(idholder1).innerHTML = "Draw!" } else if (userChoice == 1 && compchoice == 2) { document.getElementbyId(idholder1).innerHTML = "Scissors beats Paper, you lose!" } else if (userChoice == 2 && compchoice == 0) { document.getElementbyId(idholder1).innerHTML = "Rock beats Scissors, you lose!" } else if (userChoice == 2 && compchoice == 1) { document.getElementbyId(idholder1).innerHTML = "Scissors beat Paper, you win!" } else if (userChoice == 2 && compchoice == 2) { document.getElementbyId(idholder1).innerHTML = "Draw!" } } </script> </head> <body> <p> <center><img src="rock.jpg" width="197" height="171" alt="rock" id="userpic" /><img src="paper.jpg" width="210" height="95" id="comppic" /><br /> <h1 id="gametext" onLoad="playGame('gametext')">ROCK PAPER SCISSORS SHOOT!</h1></center> </p> I have an assignment to code a java class that plays rock, paper, or scissors. The class can access the history of past gestures played by both itself and its opponent, but nothing else. The class will be played against others in 10,000 matches and the winner will be determined via round robin format. Other than using a greedy algorithm to determine statistically the best choice from prior gestures and basic pattern recognition I have no decent ideas. I'd appreciate any suggestions.
Hi, I'm trying to put some kind of code for some kind of facebook game but then the problem that I'm having is this code kinda broken now, which is mean not really support to the new facebook platform or new version of facebook and the facebook game have change many links in itself I try to update it but never success on this project, if someone could assist me where to start or what to do please do so will be much appreciate for the help in advance Code: javascript:( function() { var d, url, t, i; d = window.open().document; url = location.href; d.write('<p>'); if (url.match(/clearance/)) { var user_id; var pets, li, im; var pet_link, pet_id, pet_name, pet_seller, pet_price; t = document.getElementById('app7019261521_my_monies') .getElementsByTagName('a')[0].getAttribute('href'); user_id = t.substr(t.lastIndexOf("/") + 1); d.write(' HotBuys</p>'); d.write('<table><tr><td valign="top"><table>'); pets = document.getElementsByClassName('user-item on_sale'); for (i = 0; i < pets.length; i++) { im = pets[i].getElementsByTagName('img'); if (im.length > 0) { t = im[0].getAttribute('src'); } else { t = "http://static.ak.fbcdn.net/pics/s_silhouette.jpg" } li = pets[i].getElementsByClassName('text')[0].getElementsByTagName('li'); pet_link = li[0].getElementsByTagName('a')[0].getAttribute('href'); pet_id = pet_link.substr(pet_link.lastIndexOf("/") + 1); pet_name = li[0].getElementsByTagName('a')[0].firstChild.nodeValue; pet_price = li[1].getElementsByClassName('money')[0].firstChild.nodeValue; if (i%5 == 0) { d.write('<tr>'); } d.write('<td width="100px" valign="top">'); d.write('<a style="font-size:60%" rel="nofollow" target="P" href="' + pet_link + '">'); d.write('<img width="100" height="100" src="' + t + '"/></a><br/>'); d.write('<a style="font-size:60%" rel="nofollow" target="P" href="' + pet_link + '">' + pet_name + '</a><br/>'); d.write('<span style="font-size:70%">' + pet_price + '</span>'); d.write('<table><tr><td>'); d.write('<form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/buy/' + pet_id + '">'); d.write('<input name="buyer_id" type="hidden" value="' + user_id + '"/>'); d.write('<input type="submit" value="Buy"/></form></td><td>'); d.write('<form method="post" rel="nofollow" target="Q" action="http://apps.facebook.com/friendsforsale/users/buy/' + pet_id + '">'); d.write('<input name="buyer_id" type="hidden" value="' + user_id + '"/>'); d.write('<input type="submit" value="Buy"/></form></td></tr></table></td>'); if (i%5 == 4) { d.write('</tr>'); } } d.write('</table></td><td valign="top">'); d.write('<iframe name="P" width="400" height="540"></iframe>'); d.write('<iframe name="Q" width="400" height="540"></iframe>'); d.write('</td></tr></table>'); } else if (url.match(/users\/show/)) { var user_id, pet_id, pet_name, pet_value, pet_cash; var info, info_money, title_icon; var achievements, badges, badge_pages, badge_count, n_tycoon = 0, n_collar = 0; t = document.getElementById('app7019261521_my_monies') .getElementsByTagName('a')[0].getAttribute('href'); user_id = t.substr(t.lastIndexOf("/") + 1); t = url.match(/users\/show\/[0-9]+/)[0]; pet_id = t.substr(t.lastIndexOf("/") + 1); t = document.title; pet_name = t.substr(t.lastIndexOf("|") + 2); info = document.getElementsByClassName("info"); info_money = info[0].getElementsByClassName("money"); pet_value = info_money[0].firstChild.nodeValue; pet_cash = info_money[1].firstChild.nodeValue; title_icon = document.getElementsByClassName("general")[0] .getElementsByClassName("title_icon"); achievements = document.getElementsByClassName("achievements"); if (achievements.length > 0) { } d.write('</span> <span style="color:#777">value:</span> ' + pet_value); d.write(' <span style="color:#777">cash:</span> ' + pet_cash); d.write(' <a href="http://apps.facebook.com/friendsforsale/comments?a=' + user_id + '&b=' + pet_id + '" rel="nofollow" target="P">C2C</a>'); d.write(' <a href="http://apps.facebook.com/friendsforsale/users/admin_dialog/' + pet_id + '" rel="nofollow" target="P">AD</a></p>'); d.write('<table border="0" cellpadding="0" cellspacing="0"><tr>'); d.write('<td><form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/buy/' + pet_id + '">'); d.write('<input name="buyer_id" type="hidden" value="' + user_id + '"/>'); d.write('<input type="submit" value="Buy"/></form></td>'); d.write('<td><form method="post" rel="nofollow" target="Q" action="http://apps.facebook.com/friendsforsale/users/buy/' + pet_id + '">'); d.write('<input name="buyer_id" type="hidden" value="' + user_id + '"/>'); d.write('<input type="submit" value="Buy"/></form></td>'); d.write('<td><form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/update/' + pet_id + '">'); d.write('<input name="" type="submit" value="Nick"/><input name="nickname" type="text" size="10"/></form></td>'); d.write('<td><form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/sale/' + pet_id + '">'); d.write('<input name="" type="submit" value="Sale"/></form></td>'); d.write('<td><form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/release/' + pet_id + '">'); d.write('<input name="" type="submit" value="Free"/></form></td></tr></table>'); d.write('<table border="0" cellpadding="0" cellspacing="0"><tr>'); d.write('<td><form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/' + pet_id + '/comments/create">'); d.write('<input name="" type="submit" value="Comment"/><textarea rows="1" col="20" name="comment" type="text" style="vertical-align:top"></textarea></form></td>'); d.write('</tr></table>'); d.write('<iframe name="P" width="400" height="540"></iframe>'); d.write('<iframe name="Q" width="400" height="540"></iframe>'); } else { d.write(' </p>'); } d.write('</body></html>'); d.close(); } )() I'm a bit confused as I'm just learning PHP/Java, and need to display a percentage. I successfully can display a percentage, however, the decimal like any calculate displays .00000012130 whatever sometimes. How can I round the output to the nearest 10s place? <script language="javascript" type="text/javascript"> var a = "14"; var b = "25"; document.write(parseInt(a) / parseInt(b) * 100); document.write("%"); </script> This is the code I use, however, it needs to be modified so that it rounds to the nearest 10 instead of display a decimal. Is it possible to convert "xyz123456xyz789" into "123456xyz789"? What I'm trying to say is, remove the first occurence of "xyz" from the string, so that all the other occurrences of "xyz" that aren't the first one, remain. Help is appreciated. Thanks, Jazzo So say if my string was.. Code: a = "Hello"; alert(a); How do I get it to say; Code: alert("ello"); So how do I take off the 'H' in this example.. is there a function in JS to remove a string from some text but without using the replace function? I am removing a specific string from my text using and using the replace function of the match text with a non breaking space but what i really do not want to add anything to my html. The replace is been place in a visual editor box after the user adds text and save the form, this is the code i am using to replace the code, i am using a regular expression to look for <META content="MSHTML 6.00.6000.16890" name="GENERATOR"><LINK title="/iw/ewebeditpro20/ektnormal.css" href="/iw/ewebeditpro20/ektnormal.css" rel="stylesheet"> : // Pass 1 - Removes extra code checks on Regular Expression inside replace function var newstrchanged = strEscaped.replace(/^%26%2365279%3B%20%3CMETA%20content%3D%22MSHTML%20.+.stylesheet%22%3E/g, ''); Hello, I'm trying to remove one of the $ signs from this string below. I've gotten as far as removing them both. I'm having trouble removing one of them. Can someone help? Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script> $(document).ready(function(){ /*v = $("span.name").html().replace(/,/g,''); $("span.name").html(v);*/ v = $("div.test td").html().replace(/\$/g,''); $("div.test td").html(v); }); </script> <!-- <span class="name"><span class="gost">Yahoo</span>, </span>--> <div class="test"> <table><tr> <td>3-7 Business Days $$0</td></tr></table> </div> </body> </html> Ok so i want to work on an EASY basic game. As simple as Guess what number... But there are some twist... Ok So here is my example... (HTML, i know this.)I'm Guessing a number 1-99. What is it? (java) Lets say its 66 and they guess 53, have the text rusult be in a pop up window be: Too low! (java) Lets say they guess 78, have the text rusult be in a pop up window be: Too high! (java) Lets say they guess 100+, have the text rusult be in a pop up window be: Out of range! (java)But lets say they guess 66, have a text result be in a pop up window be: You've won! (java) I want a text field where you can enter your answer, and it will do the actions above. Can anyone code this? Thanks for reading! This is a simple basic game i want to make. Its a "What Am I" Riddle... The questions is (In HTML which i already know): I'm as light as a feather but no man can hold me for long. What am I? the answer is: Your Breath. (This is where the JAVASCRIPT comes in) Lets say they guess a rock, have a pop up say: Wrong Answer. Please try again. Lets say they guess Your breath -OR- Breath, have a pop up say: Correct! I want a text field where you can enter your answer, and if they choose ANYTHING but the 2 correct answers above, it will display please try again. Can anyone code this please? Thanks for reading. Hey all, I have a simple example below showing how when I pass in the value of the value attribute of option node, and then use if operator to check whether parameter is a string or not, even though it's a string, it converts it to false boolean and triggers the else statement rather than calling a function: Code: <body> <select> <option value="createMsg">Add Message</option> <option value="removeMsg">Remove Message</option> </select> </body> Code: var menu = { handleMenu : function(callback){ if(callback === "string"){ menu[callback](); } else { console.log("Issue occurred") } }, createMsg : function(){ var content = document.createTextNode("Please give additional information."), heading = document.createElement("h1"); heading.appendChild(content); document.body.appendChild(heading); }, removeMsg : function(){ } } document.getElementsByTagName('select')[0].onchange = function(){ menu.handleMenu(this.value)}; callback should be a string so why is it saying otherwise? Thanks for response I have a game page on my site and I am trying to protect direct access to it by .htaccess .htpasswd but is not accepting user name and password? .htaccess: AuthUserFile /home/vhosts/kandcoentertainment.freetzi.com/.htpasswd AuthType Basic AuthName "game1" <Files "cookietest.html"> Require valid-user </Files> .htpasswd test:8888 Any suggestions on why it is not working? What I would like to do is have apay and play once setup but as I am a novice and dont have a clue HELP PLEASE!!! What I have been told is - protect the files, add a client side cookie to game page then upon url payment return validate cookie giving single access and when played the user cannot replay by refresh or just typing in url because cookie expired ? I have tried to write the scripts up with no success. Hi! I am studying webdesign and we also go through a chapter of javascript-programming. Our first assignment is to create a dice game. I have written a code and in the beginning it worked, except that all the dices showed the same random number. I tried to fix that and now I do not know what I have done! In the game, you shall click on a link and the three dices will show random numbers. Here is my code: Code: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Tärningsspel</title> <script type="text/javascript" language="javascript"> function showDice(imgNr) { if (imgNr == 1) var imgUrl = "1.gif"; else if (imgNr == 2) var imgUrl = "2.gif"; else if (imgNr == 3) var imgUrl = "3.gif"; else if (imgNr == 4) var imgUrl = "4.gif"; else if (imgNr == 5) var imgUrl = "5.gif"; else if (imgNr == 6) var imgUrl = "6.gif"; document.tarning1.src = imgUrl; document.tarning2.src = imgUrl; document.tarning3.src = imgUrl; } function randomInteger() { var randNumber = Math.random(); var randNumber = Math.floor(5*randNumber)+2; return randNumber; } function showRandomPict() { var imgNr = randomInteger(6); showDice(imgNr); var imgName = "tarning1" + imgNr; var imgName = "tarning2" + imgNr; var imgName = "tarning3" + imgNr; } function PlayAll(){ diceSwitch('tarning1', 'text1'); diceSwitch('tarning2', 'text2'); diceSwitch('tarning3', 'text3'); } function diceSwitch(randNumber,textRuta){ var randNumber = randomInteger(); } </script> </head> <body> <p><b>Tärning 1:</b><br /><span id="text1">1</span></p> <p><b>Tärning 2:</b><br /><span id="text2">2</span></p> <p><b>Tärning 3:</b><br /><span id="text3">3</span></p> <img src="1.gif" name="tarning1" onclick="javascript:diceSwitch('tarning1', 'text1')" /> <img src="2.gif" name="tarning2" onclick="javascript:diceSwitch('tarning2', 'text2')" /> <img src="3.gif" name="tarning3" onclick="javascript:diceSwitch('tarning3', 'text3')" /> <p><a href="javascript:PlayAll()">Spela alla!</a></p> </body> </html> Thank you! I am creating a guessing word game and when the user types in a guess a pop-up tells the user how many letters the user got right to the actual answer. My problem is I can't seem to display the number of letters the user guessed right. This is what the function looks like: Code: function guessing() { words = "album"; guess = document.getElementById("txt1").value; answer = document.getElementById("result").value = parseInt(); alert("You have " + answer + " matches"); used = false; for(i = 0; i<=guess.length; i++) { for(j = 0; j<=answer.length; j++) if(!used[j] && guess[i] == words) { alert("Congradulations! You got it!"); used[j] = true; count++; break; } else { count = 5; while(count > 5) { alert("Sorry, that's game over!"); count++; } } } } sorry this post is duplicated, the original post:http://www.codingforums.com/showthread.php?t=261488
Hi every1! Got a task in university to make a memory game (card matching game). Thats what i've got so far: Code: var selected = 0; var choiceOne; var choiceTwo; var matches = 0; var numOfTries = 0; var interval = 700; var gamePlace = document.getElementById("wrap"); var backcard="img/memoryBg.png"; var timeStart; var timeFinish; var time; function nameEnter(){ var name = prompt("Please enter your name"); if (name != null){ document.title = "Welcome " + name + "!"; } } function game(){ var nOfPairs = document.getElementById("nPairs").value; timeStart = new Date().getTime(); if (nOfPairs==1){ var cards=[]; cards[0] = 'img/card1.png'; cards[1] = 'img/card1.png'; } if (nOfPairs==2){ var cards=[]; cards[0] = 'img/card1.png'; cards[1] = 'img/card1.png'; cards[2] = 'img/card2.png'; cards[3] = 'img/card2.png'; cards.sort(function shuffle(){ return Math.random() - 0.5;}); } if (nOfPairs==3){ var cards=[]; cards[0] = 'img/card1.png'; cards[1] = 'img/card1.png'; cards[2] = 'img/card2.png'; cards[3] = 'img/card2.png'; cards[4] = 'img/card3.png'; cards[5] = 'img/card3.png'; cards.sort(function shuffle(){ return Math.random() - 0.5;}); } if (nOfPairs==4){ var cards=[]; cards[0] = 'img/card1.png'; cards[1] = 'img/card1.png'; cards[2] = 'img/card2.png'; cards[3] = 'img/card2.png'; cards[4] = 'img/card3.png'; cards[5] = 'img/card3.png'; cards[6] = 'img/card4.png'; cards[7] = 'img/card4.png'; cards.sort(function shuffle(){ return Math.random() - 0.5;}); } if (nOfPairs==5){ var cards=[]; cards[0] = 'img/card1.png'; cards[1] = 'img/card1.png'; cards[2] = 'img/card2.png'; cards[3] = 'img/card2.png'; cards[4] = 'img/card3.png'; cards[5] = 'img/card3.png'; cards[6] = 'img/card4.png'; cards[7] = 'img/card4.png'; cards[8] = 'img/card5.png'; cards[9] = 'img/card5.png'; cards.sort(function shuffle(){ return Math.random() - 0.5;}); } if (nOfPairs==6){ var cards=[]; cards[0] = 'img/card1.png'; cards[1] = 'img/card1.png'; cards[2] = 'img/card2.png'; cards[3] = 'img/card2.png'; cards[4] = 'img/card3.png'; cards[5] = 'img/card3.png'; cards[6] = 'img/card4.png'; cards[7] = 'img/card4.png'; cards[8] = 'img/card5.png'; cards[9] = 'img/card5.png'; cards[10] = 'img/card6.png'; cards[11] = 'img/card6.png'; cards.sort(function shuffle() { return Math.random() - 0.5;}); } if (nOfPairs==7){ var cards=[]; cards[0] = 'img/card1.png'; cards[1] = 'img/card1.png'; cards[2] = 'img/card2.png'; cards[3] = 'img/card2.png'; cards[4] = 'img/card3.png'; cards[5] = 'img/card3.png'; cards[6] = 'img/card4.png'; cards[7] = 'img/card4.png'; cards[8] = 'img/card5.png'; cards[9] = 'img/card5.png'; cards[10] = 'img/card6.png'; cards[11] = 'img/card6.png'; cards[12] = 'img/card7.png'; cards[13] = 'img/card7.png'; cards.sort(function shuffle(){ return Math.random() - 0.5;}); } if (nOfPairs==8){ var cards=[]; cards[0] = 'img/card1.png'; cards[1] = 'img/card1.png'; cards[2] = 'img/card2.png'; cards[3] = 'img/card2.png'; cards[4] = 'img/card3.png'; cards[5] = 'img/card3.png'; cards[6] = 'img/card4.png'; cards[7] = 'img/card4.png'; cards[8] = 'img/card5.png'; cards[9] = 'img/card5.png'; cards[10] = 'img/card6.png'; cards[11] = 'img/card6.png'; cards[12] = 'img/card7.png'; cards[13] = 'img/card7.png'; cards[14] = 'img/card8.png'; cards[15] = 'img/card8.png'; cards.sort(function shuffle(){ return Math.random() - 0.5;}); } if(nOfPairs>8||nOfPairs<1){ alert("Please enter the number from 1 to 8"); }else{ for(i = 0; i<=nOfPairs*2-1; i++){ var cardDiv = document.createElement("div"); cardDiv.setAttribute("id",""+i+""); cardDiv.style.height="65px"; cardDiv.style.width="65px"; cardDiv.style.float='left'; gamePlace.appendChild(cardDiv); document.getElementById(""+i+"").innerHTML='<img src="img/memoryBg.png">'; cardDiv.onclick=function(){cardClick(this.id);}; } } function cardClick(card){ if (selected==2){ return ; } if (selected==0){ choiceOne=card; document.images[card].src = cards[card]; selected = 1; }else { selected = 2; choiceTwo = card; document.images[card].src =cards[card]; var timer=setInterval(checking,interval); } function checking() { clearInterval(timer); numOfTries++; document.getElementById("tries").innerHTML = numOfTries; if (cards[choiceTwo]==cards[choiceOne]){ matches++; document.images[choiceOne].src = "img/memoryBgI.png"; document.images[choiceTwo].src = "img/memoryBgI.png"; //choiceTwo.onclick=null; } else { document.images[choiceOne].src = "img/memoryBg.png"; document.images[choiceTwo].src = "img/memoryBg.png"; selected = 0; return ; } if (matches == nOfPairs){ timeFinish = new Date().getTime(); time = Math.round (((timeFinish - timeStart)/1000)); alert("Congrats! You needed " + numOfTries + " tries, and " + time + " seconds."); } selected = 0; return ; } } } so the problem is, that I can just click 2 times on one card and it will look like a coincidence. My second problem is that when I have a real coincidence, I can still click on that card (by "real coincidence" i mean two same pics. so when i find them, they have to be not active, and when im clicking on them, they should just simply do nothing.). Can someone help me? Hello everyone. I have a tic tac toe game I am working on and I managed to make it so you can place X's and O's respectively. My next problem is making a win condition so it checks to see if the X's won the game or the O's did. Here is what I have so far. Edit fiddle - JSFiddle What I am basically thinking is that when you are clicking I want whatever letter it is that is placed to be saved and then I can check to see if all 3 are equal to that letter. It is a bit hard to explain. Essentially I want to make a win condition. If anyone could throw some assistance my way that would be great. I know for sure it requires a lot of checks because there are so many different ways of winning, I just need to know that initial one. Thank you very much. What I'm trying to achieve is it initialises a number between 1-2000 randomly. When the submit button is clicked it simply returns if the number that is in putted is higher or lower than the randomly initialised number. External JavaScript: Html Code: <html> <head> <script type="text/javascript" src="jsscri.js"></script> </head> <body onload="initialisation ()"> <form name="exampleform"> <h3> Number: <input name="number" type="text" onchange='checkNumber( this.value );'> </h3> <p> <input name="submit" type="button" value="Guess" onclick= 'checkValue()';/> </p> </body> </html> If you load this onto a webpage you'll see what i'm trying to do. I tried deleting the rest of the code to keep the size of the code down. |