In short, the code picks up to 9 different id
s from li
in jailplayer
.
If a hillside, it shall save the value of the id, and then checks if there are more li
, up to 9 pcs.
Then I save this in an array, depending on how many id
s were found.
This looks like a mess. Can someone help me shorten this code and make it easier to read?
if ($("#jailplayer").children("li").length >= 1) {
var player1 = $("#jailplayer").find("li:nth-child(1)").attr("id");
sender = sender + ',';
sender = sender + player1;
} else {
var player1 = '';
}
console.log('done one, searching 2');
if ($("#jailplayer").children("li").length >= 2) {
var player2 = $("#jailplayer").find("li:nth-child(2)").attr("id");
sender = sender + ',';
sender = sender + player2;
}else {
var player2 = '';
}
if ($("#jailplayer").children("li").length >= 3) {
var player3 = $("#jailplayer").find("li:nth-child(3)").attr("id");
sender = sender + ',';
sender = sender + player3;
}else {
var player4 = '';
}
if ($("#jailplayer").children("li").length >= 4) {
var player4 = $("#jailplayer").find("li:nth-child(4)").attr("id");
sender = sender + ',';
sender = sender + player4;
}else {
var player4 = '';
}
if ($("#jailplayer").children("li").length >= 5) {
var player5 = $("#jailplayer").find("li:nth-child(5)").attr("id");
sender = sender + ',';
sender = sender + player5;
}else {
var player5 = '';
}
if ($("#jailplayer").children("li").length >= 6) {
var player6 = $("#jailplayer").find("li:nth-child(6)").attr("id");
sender = sender + ',';
sender = sender + player6;
}else {
var player6 = '';
}
if ($("#jailplayer").children("li").length >= 7) {
var player7 = $("#jailplayer").find("li:nth-child(7)").attr("id");
sender = sender + ',';
sender = sender + player7;
}else {
var player7 = '';
}
if ($("#jailplayer").children("li").length >= 8) {
var player8 = $("#jailplayer").find("li:nth-child(8)").attr("id");
sender = sender + ',';
sender = sender + player8;
player8 .= ',';
}else {
var player8 = '';
}
if ($("#jailplayer").children("li").length >= 9) {
var player9 = $("#jailplayer").find("li:nth-child(9)").attr("id");
sender = sender + ',';
sender = sender + player9;
}else {
var player9 = '';
}
console.log('adding ize');
var ize =[sender];