Dear programmers I'm working on a website project to help students to learn English. The site supposed to give a student random words then the student must sort these words correctly to make sentences or questions. I am stuck at elements movement, the buttons must move to next each other when the student clicks on them, I've made the buttons move but it's not working as I want. at last Thanks for your patience This is my code Note: I'm not an English native speaker sorry if there is an error in my language.
var question=["Does","he","play","chess","?"];
var randquestion=shuffle(question);
document.getElementById("message").innerHTML=question.length;
var temp="";
for(var i=0;i<question.length;i++)
{
temp+="<button name=btn class='button button1' id='animate' type=button onclick='myFunction'>"+randquestion[i]+"</button>";
}
document.getElementById("message").innerHTML=temp;
for(var i=0;i<question.length;i++)
{
document.getElementsByName("btn")[i].onclick=myFunction;
}
function myFunction()
{
myMoveDown(this);
}
var id = null;
function myMoveDown(elm) {
var elem = elm;
var pos = 0;
var pos2=0;
clearInterval(id);
id = setInterval(frame, 3);
function frame() {
if (pos == 250) {
clearInterval(id);
} else {
pos+=10; pos2-=10;
elem.style.top= pos + "px";
elem.style.left = pos2 + "px";
}
}
}
function getRndInteger(min, max) {
//This JavaScript function always returns
//a random number between min and max (both included)
return Math.floor(Math.random() * (max - min + 1) ) + min;
}
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
body {
background-color: #1E0555;
text-align: center;
}
.button {
border: 4px;
border-radius: 5px;
border-color: black;
color:black;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
margin: 1px 4px;
cursor: pointer;
}
.button1 {background-color: #b1f01f;} /* Green */
.divStyle{
margin: 100px 4px;
text-align:left;
}
#animate {
border: 4px;
border-radius: 5px;
border-color: black;
color:black;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
margin: 1px 4px;
cursor: pointer;
position:relative;
background-color: #b1f01f;;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Learn English" />
<title>Document</title>
<link rel="stylesheet" href="CSS/myStyle.css" />
</head>
<body>
<div id="message"></div>
<div class="divStyle" id="message2"></div>
<script src="index.js"></script>
</body>
</html>