JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
Question 3
<div class="question_div">
<p>In a camp, there is a meal for 200 children or 120 men. If 150 children have taken the meal, how many men will be served with the remaining meal?</p>
<div class="ran">
<input type="radio" name="radio3" id="checka3" value="A">
<label for="checka3">
<p>31</p>
</label>
</div>
<div class="ran"><input type="radio" name="radio3" id="checkb3" value="B"><label for="checkb3">
<p>30</p>
</label>
</div>
<div class="ran"><input type="radio" name="radio3" id="checkc3" value="C"><label for="checkc3">
<p>29</p>
</label>
</div>
<div class="ran"><input type="radio" name="radio3" id="checkd3" value="D"><label for="checkd3">
<p>35</p>
</label>
</div>
<div class="ran"><input type="radio" name="radio3" id="checke3" value="E"><label for="checke3">
<p>None of these</p>
</label>
</div>
</div>
CSS
label {
display: inline-block;
margin-left: 5px;
}
.ran {
float: left;
width: 300px;
}
div:nth-child(even) {
clear: left;
}
JavaScript
window.onload = function() {
randomize();
};
function randomize() {
let questions = $(".question_div");
let divCollection = questions.find(".ran");
let divs = Array.from(divCollection);
shuffleArray(divs);
for (const div of divs) {
questions.append(div);
}
}
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}