Skip to content

Instantly share code, notes, and snippets.

@egibney
Last active November 25, 2019 17:43
Show Gist options
  • Save egibney/dedd5ce0017693c8b51ccaf851ac69fe to your computer and use it in GitHub Desktop.
Save egibney/dedd5ce0017693c8b51ccaf851ac69fe to your computer and use it in GitHub Desktop.
function setContent() {
url = data[user_index].pictures[pic_index].url;
document.getElementById('dog_image').src = url;
}
function next () {
pics_in_user = data[user_index].pictures.length;
if (pic_index === pics_in_user-1) {
pic_index = 0;
if (user_index === data.length-1) {
alert('This is the end');
} else {
user_index = user_index + 1;
}
} else {
pic_index = pic_index + 1;
};
setContent();
};
function previous () {
pics_in_user = data[user_index].pictures.length;
if (pic_index === 0) {
if (user_index === 0) {
alert('This is the beginning');
} else {
user_index = user_index - 1;
}
} else {
pic_index = pic_index - 1;
}
setContent();
};
function setProgress() {
pics_in_user = data[user_index].pictures.length;
}
var data = [
{
"id": 1,
"name": "name1",
"pictures": [
{
"id": 1,
"url": "https://images.dog.ceo/breeds/retriever-golden/n02099601_7588.jpg"
},
{
"id": 2,
"url": "https://images.dog.ceo/breeds/beagle/n02088364_17294.jpg"
}
]
},
{
"id": 2,
"name": "name2",
"pictures": [
{
"id": 3,
"url": "https://images.dog.ceo/breeds/coonhound/n02089078_353.jpg"
},
{
"id": 4,
"url": "https://images.dog.ceo/breeds/springer-english/n02102040_3006.jpg"
}
]
}
];
var user_index = 0;
var pic_index = 0;
url = data[0].pictures[0].url;
document.getElementById('dog_image').src = url;
document.getElementById('progress').style.width = '10px';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment