Created
March 24, 2025 19:42
-
-
Save primaryobjects/f4032422353f0353dc334f7674c37687 to your computer and use it in GitHub Desktop.
CodeSignal Frontend Quiz Shifting Digits Question https://app.codesignal.com/practice-question/question/frontend?context=otherTypes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body class="main"> | |
<h1>Frontend Task</h1> | |
<div> | |
<div id='left-box'><button id='left' class='btn-box left-shift-button'><<</button></div> | |
<div id='division'> | |
<div class='box'>1</div> | |
<div class='box'>2</div> | |
<div class='box'>3</div> | |
<div class='box'>4</div> | |
<div class='box'>5</div> | |
</div> | |
<div id='right-box'><button id='right' class='btn-box right-shift-button'>>></button></div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const btnLeft = document.getElementById('left'); | |
const btnRight = document.getElementById('right'); | |
const divisions = document.getElementsByClassName('box'); | |
btnLeft.onclick = () => { | |
let temp; | |
for (let i=0; i<divisions.length; i++) { | |
if (!i) { | |
temp = divisions[i].innerText; | |
const next = divisions[i+1].innerText; | |
divisions[i].innerText = next; | |
} | |
else if (i < divisions.length - 1) { | |
const current = divisions[i].innerText; | |
const next = divisions[i+1].innerText; | |
divisions[i].innerText = next; | |
divisions[i-1].innerText = current; | |
} | |
else { | |
divisions[i].innerText = temp; | |
} | |
} | |
}; | |
btnRight.onclick = () => { | |
let temp; | |
for (let i=divisions.length - 1; i >= 0; i--) { | |
if (i === divisions.length - 1) { | |
temp = divisions[i].innerText; | |
const prev = divisions[i-1].innerText; | |
divisions[i].innerText = prev; | |
} | |
else if (i > 0) { | |
const current = divisions[i].innerText; | |
const prev = divisions[i-1].innerText; | |
divisions[i].innerText = prev; | |
divisions[i+1].innerText = current; | |
} | |
else { | |
divisions[i].innerText = temp; | |
} | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.btn-box { | |
padding: 4px; | |
font-weight: bolder; | |
font-size: 20px; | |
float: left; | |
margin: 0 10px 0 10px; | |
} | |
#division div { | |
font-size: 30px; | |
float: left; | |
margin: 0 10px 0 10px; | |
} | |
#division div:first-child { | |
margin-left: 20px; | |
} | |
#division div:last-child { | |
margin-right: 20px; | |
} |
Author
primaryobjects
commented
Mar 24, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment