From 85b175821f435385c2e1125068eaa0931acda46d Mon Sep 17 00:00:00 2001 From: dzemuner <61262448+dzemuner@users.noreply.github.com> Date: Fri, 28 Feb 2020 21:21:17 -0500 Subject: [PATCH] Update block.html - Alternate image Simple change that reduces the code and shows alternating images for each movement. --- public/block.html | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/public/block.html b/public/block.html index e7999c4..5a59760 100644 --- a/public/block.html +++ b/public/block.html @@ -11,12 +11,8 @@ img = document.getElementById("PacMan"); pos += 20; img.style.left = pos + "px"; - if (flag === 1) { - img.src = url + '/pac?id=' + flag; // use flag to choose image - flag = 2; - } else { - flag = 1; - } + flag = (pos % 40 === 20) ? 1 : 2; // alternate flag value beetwen 0 and 1 + img.src = url + '/pac?id=' + flag; // use flag to choose image // send position data to Server in url fetch(url + '/set?x=' + pos); } @@ -26,4 +22,4 @@
Click on PacMan and the position will be sent to the server".