Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let picture = 0;
  2.  
  3. const Character = function (name) {
  4.   this.name = name;
  5.   this.votes = 0;
  6. };
  7.  
  8. const characters = [
  9.   new Character('daenarys-targaryen'),
  10.   new Character('maester-varys'),
  11.   new Character('margarey-tyrell'),
  12.   new Character('petyr-baelish'),
  13.   new Character('samwell-tarly')
  14. ];
  15.  
  16. const updateImage = function () {
  17.   const character = characters[picture];
  18.   const image = `<li><img src='images/${character.name}-1920.jpg' alt='samwell' title='${character.name}'></li>`;
  19.   $('.carousel').html(image);
  20. };
  21.  
  22. const nextImage = function () {
  23.   if (picture < characters.length - 1) picture += 1;
  24.   updateImage();
  25. };
  26.  
  27. const previousImage = function () {
  28.   if (picture > 0) picture -= 1 ;
  29.   updateImage();
  30. };
  31.  
  32. const redrawVotes = function () {
  33.  
  34. };
  35.  
  36. const vote = function () {
  37.   characters[picture].votes += 1;
  38.   characters.forEach(character => {
  39.     console.log(`${character.name} has ${character.votes}`);
  40.   });
  41. };
  42.  
  43. $(() => {
  44.   updateImage();
  45.   $('.carrousel ')
  46.   $('.next').on('click', nextImage);
  47.   $('.previous').on('click', previousImage);
  48.   $('.vote').on('click', vote);
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement