I am experiencing an issue with retrieving images from an array. I have an array containing 6 variables that represent the paths to the images. However, when I use console.log
at the end, it returns a random variable like sk11, sk15, etc., which do not correspond to the image paths.
.controller('ArCtrl', function($scope) {
var sk11, sk12, sk13, sk14, sk15, sk16;
var kockice = ['sk11', 'sk12', 'sk13', 'sk14', 'sk15', 'sk16'];
var rank = kockice[Math.floor(Math.random() * kockice.length)];
if(rank === sk11) {
sk11 = "http://localhost:8100/img/1.jpg";
rank = sk11;
} else if(rank === sk12) {
sk12 = "http://localhost:8100/img/2.jpg";
rank = sk12;
} else if(rank === sk13) {
sk13 = "http://localhost:8100/img/3.jpg";
rank = sk13;
} else if(rank === sk14) {
sk14 = "http://localhost:8100/img/4.jpg";
rank = sk14;
} else if(rank === sk15) {
sk15 = "http://localhost:8100/img/5.jpg";
rank = sk15;
} else if(rank === sk16) {
sk16 = "http://localhost:8100/img/6.jpg";
rank = sk16;
}
console.log(rank); // Returns a random value from the kockice array
console.log(sk11); // Displays undefined, need to troubleshoot the reason