<html>
<head>
</head>
<body>
<script>
var elemdiv = [];
var elemdiv2 = [];
var elemsel = [];
for (var i = 0; i< 5;i++)
{
elemdiv[i] = document.createElement('div');
elemdiv[i].innerHTML = randomSymbol();
elemdiv[i].style.position = 'absolute';
elemdiv[i].style.left = i*100 +25;
elemdiv[i].style.color = 'red';
document.body.appendChild(elemdiv[i]);
elemdiv2[i] = document.createElement('div');
elemdiv2[i].innerHTML = randomSymbol();
elemdiv2[i].style.position = 'absolute';
elemdiv2[i].style.left = i*100 +25;
elemdiv2[i].style.top = 100;
elemdiv2[i].style.color = 'red';
document.body.appendChild(elemdiv2[i]);
elemsel[i]= document.createElement('select');
AppendOption(elemsel[i]);
elemsel[i].style.position = 'absolute';
elemsel[i].style.left = i*100;
elemsel[i].style.top = 50;
document.body.appendChild(elemsel[i]);
}
var btn = document.createElement("button");
var t = document.createTextNode("Проверить");
btn.appendChild(t);
btn.style.position = 'absolute';
btn.style.top = 250;
btn.onclick = OnclickButton;
document.body.appendChild(btn);
function OnclickButton()
{
var counter = 0;
for (var i = 0; i< 5;i++)
{
var state = 0;
if (elemdiv[i].innerText > elemdiv2[i].innerText)
{
state = 1;
ShowResult(">",i);
}
else if (elemdiv[i].innerText < elemdiv2[i].innerText)
{
state = 2;
ShowResult("<",i);
}
else
{
ShowResult("=",i);
state = 3;
}
if (elemsel[i].value == state) counter++;
}
alert("Количество совпадений " +counter);
}
function ShowResult(sign,index){
var result = document.createElement('div');
result.innerHTML = elemdiv[index].innerText +sign+elemdiv2[index].innerText;
result.style.position = 'absolute';
result.style.left = index*100 +25;
result.style.top = 200;
result.style.color = 'blue';
document.body.appendChild(result);
}
function randomSymbol() {
var symbols = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";
return symbols.substr(Math.random()*symbols.length, 1);
}
function AppendOption(selector)
{
var option = document.createElement('option');
option.value = '1';
option.appendChild(document.createTextNode('Больше'));
selector.appendChild(option);
option = document.createElement('option');
option.value = '2';
option.appendChild(document.createTextNode('Меньше'));
selector.appendChild(option);
option = document.createElement('option');
option.value = '3';
option.appendChild(document.createTextNode('Равно'));
selector.appendChild(option);
}
</script>
</body>
</html>
|