Click here to Skip to main content
15,881,867 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Javascript syntax Pin
NithyaKumarJai25-Nov-18 18:23
NithyaKumarJai25-Nov-18 18:23 
Questionunexpected result function autocomplete() Jquery Pin
serenimus21-Nov-18 7:15
serenimus21-Nov-18 7:15 
AnswerRe: unexpected result function autocomplete() Jquery Pin
Richard Deeming21-Nov-18 8:16
mveRichard Deeming21-Nov-18 8:16 
GeneralRe: unexpected result function autocomplete() Jquery Pin
serenimus22-Nov-18 6:11
serenimus22-Nov-18 6:11 
GeneralRe: unexpected result function autocomplete() Jquery Pin
serenimus22-Nov-18 6:13
serenimus22-Nov-18 6:13 
GeneralRe: unexpected result function autocomplete() Jquery Pin
Richard Deeming22-Nov-18 8:41
mveRichard Deeming22-Nov-18 8:41 
GeneralRe: unexpected result function autocomplete() Jquery Pin
serenimus1-Dec-18 0:19
serenimus1-Dec-18 0:19 
QuestionHello Pin
Member 1406106620-Nov-18 8:15
Member 1406106620-Nov-18 8:15 
Ive just started to learn JS and Ive been stuck on a memory game script Ive been messing with. Ive finally got it able to accept images, instead of text, but when it matches any 2 the cards just turn back over :/ Also when I hit the image card, the whole game freezes. Help please? Smile | :)

Here is code below.


<pre><!DOCTYPE html>
<html>
<head>
<style>
div#memory_board{
background: url(klematis.jpg) -repeat;
border:#FF1493 5px solid;
width:700px;
height:500px;
padding:24px;
margin:0px auto;
}
div#memory_board > div{
background: url(klematis.jpg) no-repeat;
border:#FF1493 1px solid;
width:71px;
height:71px;
float:left;
margin:10px;
padding:20px;
font-size:64px;
cursor:pointer;
text-align:center;
}
div#memory_board > div img {
height: 100%;
}
.picture{
background-size: cover !important
}
</style>
<script>
// Scripted By Adam Khoury in connection with the following video tutorial:
// http://www.youtube.com/watch?v=c_ohDPWmsM0
var memory_array = ['url("http://cs61a.org/assets/images/john-denero.jpg")','A','B','B','C','C','D','D','E','E','F','F','G','G','H','H','I','I','J','J','K','K','L','L'];
var memory_values = [];
var memory_tile_ids = [];
var tiles_flipped = 0;
Array.prototype.memory_tile_shuffle = function(){
var i = this.length, j, temp;
while(--i > 0){
j = Math.floor(Math.random() * (i+1));
temp = this[j];
this[j] = this[i];
this[i] = temp;
}
}
function newBoard(){
tiles_flipped = 0;
var output = '';
memory_array.memory_tile_shuffle();
for(var i = 0; i < memory_array.length; i++){
output += '<div id="tile_'+i+'" class="picture" onclick="memoryFlipTile(this,\ ' + i + ')"></div>';
}
document.getElementById('memory_board').innerHTML = output;
}
function memoryFlipTile(tile,val){
if(tile.innerHTML == "" && memory_values.length < 2){
index = memory_array[val]

if (memory_array[val].length > 20){
tile.style.backgroundImage = memory_array[val];
}
else {
tile.style.background = '#FFF';
if (index == "image"){
tile.innerHTML = "<div style='font-size: 20px'>" +index +"</div>"
}
else
{
tile.innerHTML = index;
}

}

if(memory_values.length == 0){
memory_values.push(index);
memory_tile_ids.push(tile.id);
}
else if(memory_values.length == 1){
memory_values.push(index);
memory_tile_ids.push(tile.id);
if((memory_values[0].length > 20) && (memory_values[1].length < 20) && (memory_values[0] == gsi_dict[memory_values[1]])){
console.log("go")
tiles_flipped += 2;
// Clear both arrays
phrase = "You found "+ memory_values[1] +"!"
alert(phrase)
memory_values = [];
memory_tile_ids = [];
if(tiles_flipped == memory_array.length){
alert("Great job naming those awesome GSI's. Get ready to play again!");
document.getElementById('memory_board').innerHTML = "";
newBoard();
}

}
else if((memory_values[1].length > 20) && (memory_values[0].length < 20) && (memory_values[1] == gsi_dict[memory_values[0]])){
console.log("go")
tiles_flipped += 2;
phrase = "You found "+memory_values[0] + "!"
alert(phrase)
// Clear both arrays
memory_values = [];
memory_tile_ids = [];
if(tiles_flipped == memory_array.length){
alert("Great job naming the CS61A staff. Get ready to play again!");
document.getElementById('memory_board').innerHTML = "";
newBoard();
}

}
else {
console.log("flip")
function flip2Back(){
// Flip the 2 tiles back over
var tile_1 = document.getElementById(memory_tile_ids[0]);
var tile_2 = document.getElementById(memory_tile_ids[1]);
tile_1.style.background = "url(klematis.jpg)";
tile_1.innerHTML = "";
tile_2.style.background = "url(klematis.jpg)";
tile_2.innerHTML = "";
// Clear both arrays
memory_values = [];
memory_tile_ids = [];
}
setTimeout(flip2Back, 700);
}
}
}
}
</script>
</head>
<body>
<div id="memory_board"></div>
<script>newBoard();</script>
</body>
</html></pre>
QuestionJavascript help Pin
ghazabaz8-Nov-18 15:54
ghazabaz8-Nov-18 15:54 
AnswerRe: Javascript help Pin
Richard Deeming9-Nov-18 3:49
mveRichard Deeming9-Nov-18 3:49 
QuestionRe: Javascript help Pin
ghazabaz9-Nov-18 5:55
ghazabaz9-Nov-18 5:55 
AnswerRe: Javascript help Pin
Richard Deeming9-Nov-18 7:48
mveRichard Deeming9-Nov-18 7:48 
Generalguidence for the begginners Pin
Kshitiz Thapa2-Nov-18 3:16
Kshitiz Thapa2-Nov-18 3:16 
GeneralRe: guidence for the begginners Pin
Richard MacCutchan2-Nov-18 4:00
mveRichard MacCutchan2-Nov-18 4:00 
SuggestionRe: guidence for the begginners Pin
CHill6015-Nov-18 21:46
mveCHill6015-Nov-18 21:46 
QuestionLoops Pin
Member 1403490227-Oct-18 5:06
Member 1403490227-Oct-18 5:06 
AnswerRe: Loops Pin
Richard MacCutchan27-Oct-18 5:54
mveRichard MacCutchan27-Oct-18 5:54 
QuestionSTOP VALIDATION Pin
Member 1344978425-Oct-18 0:44
Member 1344978425-Oct-18 0:44 
AnswerRe: STOP VALIDATION Pin
Afzaal Ahmad Zeeshan25-Oct-18 2:40
professionalAfzaal Ahmad Zeeshan25-Oct-18 2:40 
Questionno me funciona funcion autocomplete Jquery Pin
serenimus20-Oct-18 8:53
serenimus20-Oct-18 8:53 
AnswerRe: no me funciona funcion autocomplete Jquery Pin
Nelek20-Oct-18 8:59
protectorNelek20-Oct-18 8:59 
QuestionMap JSON data file with dates and multiple string value pairs to Angular/Chart.js Pin
Member 1201357914-Oct-18 22:08
Member 1201357914-Oct-18 22:08 
Questionaspx file don't open in chrome Pin
anasr200010-Oct-18 2:22
professionalanasr200010-Oct-18 2:22 
Questiontest regexep javascript Pin
Alboyz5-Oct-18 4:31
Alboyz5-Oct-18 4:31 
AnswerRe: test regexep javascript Pin
Richard Deeming5-Oct-18 4:48
mveRichard Deeming5-Oct-18 4:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.