在音乐厅中,某些座位比其他座位高,因此一个座位只能看到 如果前面的座位较低,则进入舞台。您的任务是找到可以看到舞台的座位 而那些不能 创建一个函数来确定每个座位(用数字表示)是否可以 “看”到前台。如果数字严格大于数字,则可以“看到”前级。 之前的数字。例如,考虑以下座位安排: //前段 [[1,2,3,2,1,1], [2,4,4,4,3,2,2], [5、5、5、5、4、4], [6,6,7,6,5,5] //从左边开始> 6> 5> 2> 1,因此所有数字都可以看到。 //同样,6> 5> 4> 2-这样所有数字都可以看到,依此类推。 如果每个数字都可以看到前台,则该函数应返回true,否则返回false。 即使是一个数字也不能。 您的音乐厅UI设计应包括以下内容: ●36个座位,每个座位都有一个输入字段 ●用于运行检查的按钮 ●在显示结果时,座位应按输入排列 ●使用绿色表示合规座位,使用红色表示任何默认座位
我试图比较行,但我没有得到想要的东西。我希望看不见的座位变成红色,但是我要让座位变成红色。
var row1 = document.querySelector(".row-1");
var row2 = document.querySelector(".row-2");
var row3 = document.querySelector(".row-3");
var row4 = document.querySelector(".row-4");
var row5 = document.querySelector(".row-5");
var row6 = document.querySelector(".row-6");
var button = document.getElementById("btn");
var row1 = [];
var row2 = [];
var row3 = [];
var row4 = [];
var row5 = [];
var row6 = [];
var seatArrange = document.querySelector(".cinema-row");
var seatArrange = ([row1,
row2,
row3,
row4,
row5,
row6
]);
document.querySelector('.seat01').style.background = 'green';
document.querySelector('.seat02').style.background = 'green';
document.querySelector('.seat03').style.background = 'green';
document.querySelector('.seat04').style.background = 'green';
document.querySelector('.seat05').style.background = 'green';
document.querySelector('.seat06').style.background = 'green';
let row1_column1 = function(seatArrange) {
for (let i = 0; i < seatArrange.length; i++) {
for (let j = 0; j < seatArrange[i].length; j++) {
if (seatArrange[i][j] < seatArrange[i + 1][j]) {
document.querySelector('.seat07').style.background = 'green';
} else {
document.querySelector('.seat07').style.background = 'red';
}
if (seatArrange[i + 1][j] < seatArrange[i + 2][j]) {
document.querySelector('.seat13').style.background = 'green';
} else {
document.querySelector('.seat13').style.background = 'red';
}
if (seatArrange[i + 2][j] < seatArrange[i + 3][j]) {
document.querySelector('.seat19').style.background = 'green';
} else {
document.querySelector('.seat19').style.background = 'red';
}
if (seatArrange[i + 3][j] < seatArrange[i + 4][j]) {
document.querySelector('.seat25').style.background = 'green';
} else {
document.querySelector('.seat25').style.background = 'red';
}
if (seatArrange[i + 4][j] < seatArrange[i + 5][j]) {
document.querySelector('.seat31').style.background = 'green';
} else {
document.querySelector('.seat31').style.background = 'red';
}
}
}
};
let row2_column2 = function(seatArrange) {
for (let i = 0; i < seatArrange.length; i++) {
for (let j = 0; j < seatArrange[i].length; j++) {
if (seatArrange[i][j + 1] < seatArrange[i + 1][j + 1]) {
document.querySelector('.seat08').style.background = 'green';
} else {
document.querySelector('.seat08').style.background = 'red';
}
if (seatArrange[i + 1][j + 1] < seatArrange[i + 2][j + 1]) {
document.querySelector('.seat14').style.background = 'green';
} else {
document.querySelector('.seat14').style.background = 'red';
}
if (seatArrange[i + 2][j + 1] < seatArrange[i + 3][j + 1]) {
document.querySelector('.seat20').style.background = 'green';
} else {
document.querySelector('.seat20').style.background = 'red';
}
if (seatArrange[i + 3][j + 1] < seatArrange[i + 4][j + 1]) {
document.querySelector('.seat26').style.background = 'green';
} else {
document.querySelector('.seat26').style.background = 'red';
}
if (seatArrange[i + 4][j + 1] < seatArrange[i + 5][j + 1]) {
document.querySelector('.seat32').style.background = 'green';
} else {
document.querySelector('.seat32').style.background = 'red';
}
}
}
};
let row3_column3 = function(seatArrange) {
for (let i = 0; i < seatArrange.length; i++) {
for (let j = 0; j < seatArrange[i].length; j++) {
if (seatArrange[i + 1][j + 2] > seatArrange[i][j + 2]) {
document.querySelector('.seat09').style.background = 'green';
} else {
document.querySelector('.seat09').style.background = 'red';
}
if (seatArrange[i + 2][j + 2] > seatArrange[i + 1][j + 2]) {
document.querySelector('.seat15').style.background = 'green';
} else {
document.querySelector('.seat15').style.background = 'red';
}
if (seatArrange[i + 3][j + 2] > seatArrange[i + 2][j + 2]) {
document.querySelector('.seat21').style.background = 'green';
} else {
document.querySelector('.seat21').style.background = 'red';
}
if (seatArrange[i + 4][j + 2] > seatArrange[i + 3][j + 2]) {
document.querySelector('.seat27').style.background = 'green';
} else {
document.querySelector('.seat27').style.background = 'red';
}
if (seatArrange[i + 5][j + 2] > seatArrange[i + 4][j + 2]) {
document.querySelector('.seat33').style.background = 'green';
} else {
document.querySelector('.seat33').style.background = 'red';
}
}
}
};
let row4_column4 = function(seatArrange) {
for (let i = 0; i < seatArrange.length; i++) {
for (let j = 0; j < seatArrange[i].length; j++) {
if (seatArrange[i][j + 3] < seatArrange[i + 1][j + 3]) {
document.querySelector('.seat10').style.background = 'green';
} else {
document.querySelector('.seat10').style.background = 'red';
}
if (seatArrange[i + 1][j + 3] < seatArrange[i + 2][j + 3]) {
document.querySelector('.seat16').style.background = 'green';
} else {
document.querySelector('.seat16').style.background = 'red';
}
if (seatArrange[i + 2][j + 3] < seatArrange[i + 3][j + 3]) {
document.querySelector('.seat22').style.background = 'green';
} else {
document.querySelector('.seat22').style.background = 'red';
}
if (seatArrange[i + 3][j + 3] < seatArrange[i + 4][j + 3]) {
document.querySelector('.seat28').style.background = 'green';
} else {
document.querySelector('.seat28').style.background = 'red';
}
if (seatArrange[i + 4][j + 3] < seatArrange[i + 5][j + 3]) {
document.querySelector('.seat34').style.background = 'green';
} else {
document.querySelector('.seat34').style.background = 'red';
}
}
}
};
let row5_column5 = function(seatArrange) {
for (let i = 0; i < seatArrange.length; i++) {
for (let j = 0; j < seatArrange[i].length; j++) {
if (seatArrange[i][j + 4] < seatArrange[i + 1][j + 4]) {
document.querySelector('.seat11').style.background = 'green';
} else {
document.querySelector('.seat11').style.background = 'red';
}
if (seatArrange[i + 1][j + 4] < seatArrange[i + 2][j + 4]) {
document.querySelector('.seat17').style.background = 'green';
} else {
document.querySelector('.seat17').style.background = 'red';
}
if (seatArrange[i + 2][j + 4] < seatArrange[i + 3][j + 4]) {
document.querySelector('.seat23').style.background = 'green';
} else {
document.querySelector('.seat23').style.background = 'red';
}
if (seatArrange[i + 3][j + 4] < seatArrange[i + 4][j + 4]) {
document.querySelector('.seat29').style.background = 'green';
} else {
document.querySelector('.seat29').style.background = 'red';
}
if (seatArrange[i + 4][j + 4] < seatArrange[i + 5][j + 4]) {
document.querySelector('.seat35').style.background = 'green';
} else {
document.querySelector('.seat35').style.background = 'red';
}
}
}
};
let row6_column6 = function(seatArrange) {
for (let i = 0; i < seatArrange.length; i++) {
for (let j = 0; j < seatArrange[i].length; j++) {
if (seatArrange[i][j + 5] < seatArrange[i + 1][j + 5]) {
document.querySelector('.seat12').style.background = 'green';
} else {
document.querySelector('.seat12').style.background = 'red';
}
if (seatArrange[i + 1][j + 5] < seatArrange[i + 2][j + 5]) {
document.querySelector('.seat18').style.background = 'green';
} else {
document.querySelector('.seat18').style.background = 'red';
}
if (seatArrange[i + 2][j + 5] < seatArrange[i + 3][j + 5]) {
document.querySelector('.seat24').style.background = 'green';
} else {
document.querySelector('.seat24').style.background = 'red';
}
if (seatArrange[i + 3][j + 5] < seatArrange[i + 4][j + 5]) {
document.querySelector('.seat30').style.background = 'green';
} else {
document.querySelector('.seat30').style.background = 'red';
}
if (seatArrange[i + 4][j + 5] < seatArrange[i + 5][j + 5]) {
document.querySelector('.seat36').style.background = 'green';
} else {
document.querySelector('.seat36').style.background = 'red';
}
}
}
};
<h1>Concert Hall</h1>
<div class="concert">
<div class="seating-arrangement center">
<div class="cinema-row row-1">
<input type="text" class="seat01">
<input type="text" class="seat02">
<input type="text" class="seat03">
<input type="text" class="seat04">
<input type="text" class="seat05">
<input type="text" class="seat06">
</div>
<div class="cinema-row row-2">
<input type="text" class="seat07">
<input type="text" class="seat08">
<input type="text" class="seat09">
<input type="text" class="seat10">
<input type="text" class="seat11">
<input type="text" class="seat12">
</div>
<div class="cinema-row row-3">
<input type="text" class="seat13">
<input type="text" class="seat14">
<input type="text" class="seat15">
<input type="text" class="seat16">
<input type="text" class="seat17">
<input type="text" class="seat18">
</div>
<div class="cinema-row row-4">
<input type="text" class="seat19">
<input type="text" class="seat20">
<input type="text" class="seat21">
<input type="text" class="seat22">
<input type="text" class="seat23">
<input type="text" class="seat24">
</div>
<div class="cinema-row row-5">
<input type="text" class="seat25">
<input type="text" class="seat26">
<input type="text" class="seat27">
<input type="text" class="seat28">
<input type="text" class="seat29">
<input type="text" class="seat30">
</div>
<div class="cinema-row row-6">
<input type="text" class="seat31">
<input type="text" class="seat32">
<input type="text" class="seat33">
<input type="text" class="seat34">
<input type="text" class="seat35">
<input type="text" class="seat36">
</div>
</div>
<button id="btn">Button</button>
</div>