hoy les quisiese pedir ayuda en un pequeño proyecto que estoy realizando resulta que estoy haciendo una especie de pokedex con imágenes. bueno el principal problema radica que yo agregue un botón donde si le doy click este me agrega al pokemon que yo selecciono a mi equipo, al yo darle click este se me agrega en la posición 1 de mi equipo todo bien, pero al darle nuevamente se agrega nuevamente a la posición 1 de mi equipo, cuando debería ser la posición 2 y luego la 3 sucesivamente. y todo esto lo tengo que hacer a puro javascritp.
Por si no me explico bien dejare un vídeo para que se vea mas gráficamente lo que pido.
Video: https://www.youtube.com/watch?v=ZowuLKj2UW0
Proyecto: https://mega.nz/#!CrAFCCDQ!seMg3E4ysC26IYI3GDnF7IxawqidLRjwfQXtOCp-RJg
Y aca todo el codigo JavaScript Y el Html
function pokeimagen(id){
let pokeimg=document.getElementById('pokedes');
let pokechange =document.getElementById("pokechange");
//alert(this.id)
if(id=="bullbasaur"){
pokeimg.src="img/bullbasaur.jpg";
pokechange.setAttribute("name","bullbasaur");
}
if(id=="pikachu"){
pokeimg.src="img/PikachuDex.jpg";
pokechange.setAttribute("name","pikachu");
}
if(id=="charmander"){
pokeimg.src="img/charmander.jpg";
pokechange.setAttribute("name","charmander");
}
if(id=="snorlax"){
pokeimg.src="img/snorlax.jpg";
pokechange.setAttribute("name","snorlax");
}
if(id=="eevee"){
pokeimg.src="img/eevee.jpg";
pokechange.setAttribute("name","eevee");
}
if(id=="psyduck"){
pokeimg.src="img/psyduck.jpg";
pokechange.setAttribute("name","psyduck");
}
if(id=="squirtle"){
pokeimg.src="img/squirtle.jpg";
pokechange.setAttribute("name","squirtle");
}
if(id=="jigglypuff"){
pokeimg.src="img/jigglypuff.jpg";
pokechange.setAttribute("name","jigglypuff");
}
}
var i=1;
function change(name){
/*
aca probe otro metodo:
var pokethead= document.getElementsByTagName("thead")[0];
let filas=pokethead.getElementsByTagName("tr");
let columna=filas[i].getElementsByTagName("td");
let pokeimg=columna[i].getElementsByTagName("img");
if(name=="pikachu"){
pokeimg.src="img/pikachu.png";
i++;
}
if(name=="charmander"){
pokeimg.src="img/charmander.png";
i++;
}
*/
if(i=1){
if(name=="pikachu"){
let pokeimg=document.getElementById("poke1");
pokeimg.src="img/pikachu.png"
i++;
return 1;
}
if(name=="bullbasaur"){
let pokeimg=document.getElementById("poke1");
pokeimg.src="img/bullbasaur.png"
i++;
return 1;
}
if(name=="eevee"){
let pokeimg=document.getElementById("poke1");
pokeimg.src="img/eevee.png"
i++;
return 1;
}
if(name=="charmander"){
let pokeimg=document.getElementById("poke1");
pokeimg.src="img/charmander.png"
i++;
return 1;
}
if(name=="jigglypuff"){
let pokeimg=document.getElementById("poke1");
pokeimg.src="img/jigglypuff.png"
i++;
return 1;
}
if(name=="squirtle"){
let pokeimg=document.getElementById("poke1");
pokeimg.src="img/squirtle.png"
i++;
return 1;
}
if(name=="snorlax"){
let pokeimg=document.getElementById("poke1");
pokeimg.src="img/snorlax.png"
i++;
return 1;
}
if(name=="psyduck"){
let pokeimg=document.getElementById("poke1");
pokeimg.src="img/psyduck.png"
i++;
return 1;
}
}
if(i=2){
if(name=="pikachu"){
let pokeimg=document.getElementById("poke2");
pokeimg.src="img/pikachu.png"
i++;
return 1;
}
if(name=="bullbasaur"){
let pokeimg=document.getElementById("poke2");
pokeimg.src="img/bullbasaur.png"
i++;
return 1;
}
if(name=="eevee"){
let pokeimg=document.getElementById("poke2");
pokeimg.src="img/eevee.png"
i++;
return 1;
}
if(name=="charmander"){
let pokeimg=document.getElementById("poke2");
pokeimg.src="img/charmander.png"
i++;
return 1;
}
if(name=="jigglypuff"){
let pokeimg=document.getElementById("poke2");
pokeimg.src="img/jigglypuff.png"
i++;
return 1;
}
if(name=="squirtle"){
let pokeimg=document.getElementById("poke2");
pokeimg.src="img/squirtle.png"
i++;
return 1;
}
if(name=="snorlax"){
let pokeimg=document.getElementById("poke2");
pokeimg.src="img/snorlax.png"
i++;
return 1;
}
if(name=="psyduck"){
let pokeimg=document.getElementById("poke2");
pokeimg.src="img/psyduck.png"
i++;
return 1;
}
}
}
<!DOCTYPE html>
<html>
<head>
<title >Pokeproyect</title>
<link rel="icon" type="image/png" href="img/pokecel.png"/>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/Estilo.css">
<script type="text/javascript" src="js/pokejs.js"></script>
</head>
<body>
<header>
<a name="pokedex"></a>
<img src="img/camera.png">
PokeCheap
</header>
<main>
<div class="pokediv">
<table>
<tr>
<td class="pokedes">
<img src="img/PikachuDex.jpg" class="pokeimagen" id="pokedes">
</td>
<td style="text-align: center;">
<div style="text-align:center; font-size:20px; color:white; margin-top:20px"> Agregar </div>
<img src="img/fight.png" class="pokecambio" id="pokechange" onclick="change(this.name)" name="pikachu" onmouseover="this.width=60;this.height=60;" onmouseout="this.width=64;this.height=64;">
</td>
<td>
<table class="pokeback">
<thead>
<tr>
<td class="pokeball">
<img src="img/pokeball.png" id="poke1">
</td>
<td class="pokeball">
<img src="img/pokeball.png" id="poke2">
</td>
</tr>
<tr>
<td class="pokeball">
<img src="img/pokeball.png" id="poke3">
</td>
<td class="pokeball">
<img src="img/pokeball.png" id="poke4">
</td>
</tr>
<tr>
<td class="pokeball">
<img src="img/pokeball.png" id="poke5">
</td>
<td class="pokeball">
<img src="img/pokeball.png" id="poke6">
</td>
</tr>
</thead>
</table>
</td>
</tr>
</table>
</div>
<section>
<table class="pokemovimiento">
<div style="text-align:center;">
<img src="img/backpack.png" > Poke-Mochila
</div>
<tr>
<td class="pokeamigos" onclick="pokeimagen(this.id)" id="pikachu">
<a href="#pokedex"><img src="img/pikachu.png" onmouseover="this.width=60;this.height=60;" onmouseout="this.width=64;this.height=64;"></a>
</td>
<td class="pokeamigos" onclick="pokeimagen(this.id)" id="charmander">
<a href="#pokedex"><img src="img/charmander.png" onmouseover="this.width=60;this.height=60;" onmouseout="this.width=64;this.height=64;"></a>
</td>
<td class="pokeamigos" onclick="pokeimagen(this.id)" id="snorlax">
<a href="#pokedex"><img class="img" src="img/snorlax.png" onmouseover="this.width=60;this.height=60;" onmouseout="this.width=64;this.height=64;"></a>
</td>
<td class="pokeamigos" onclick="pokeimagen(this.id)" id="eevee">
<a href="#pokedex"><img src="img/eevee.png" onmouseover="this.width=60;this.height=60;" onmouseout="this.width=64;this.height=64;"></a>
</td>
</tr>
<tr>
<td class="pokeamigos" onclick="pokeimagen(this.id)" id="bullbasaur">
<a href="#pokedex"><img src="img/bullbasaur.png" onmouseover="this.width=60;this.height=60;" onmouseout="this.width=64;this.height=64;"></a>
</td>
<td class="pokeamigos" onclick="pokeimagen(this.id)" id="psyduck">
<a href="#pokedex"><img src="img/psyduck.png" onmouseover="this.width=60;this.height=60;" onmouseout="this.width=64;this.height=64;"></a>
</td>
<td class="pokeamigos" onclick="pokeimagen(this.id)" id="squirtle">
<a href="#pokedex"><img src="img/squirtle.png" onmouseover="this.width=60;this.height=60;" onmouseout="this.width=64;this.height=64;"></a>
</td>
<td class="pokeamigos" onclick="pokeimagen(this.id)" id="jigglypuff">
<a href="#pokedex"><img src="img/jigglypuff.png" onmouseover="this.width=60;this.height=60;" onmouseout="this.width=64;this.height=64;"></a>
</td>
</tr>
</table>
</section>
</main>
</body>
</html>