본문 바로가기
Javascript

계산기2

by Antonio Bae 2023. 7. 14.

큐1


<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}

.dQ {
width: 200px;
height: 40px;
background-color: blue;
color: white;
text-align: right;
font-size: 35px;
line-height: 38px;
}
</style>
</head>

<body>
<div id="dQ" class="dQ"></div>
<script>
function OriginalQueue(qId) {
this.qId = qId;
this.qArray = [];
this.pushItem = function (qItem) { this.qArray.push(qItem); }
this.shiftItem = function () { }
this.countItems = function () { }
this.displayQueue = function () { document.getElementById("dQ").innerHTML += this.qArray; }
}
let zardQueue = new OriginalQueue("Zard");
zardQueue.pushItem("Z");
zardQueue.displayQueue();
</script>
</body>

</html>

A,B를 넣고 B를 빼기

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}

.dQ {
width: 200px;
height: 40px;
background-color: blue;
color: white;
text-align: right;
font-size: 35px;
line-height: 38px;
}
</style>
</head>

<body>
<div id="dQ" class="dQ"></div>
<script>
function OriginalQueue(qId) {
this.qId = qId;
this.qArray = [];
this.pushItem = function (qItem) {
this.qArray.push(qItem);
this.displayQueue();
alert("Push Item: " + qItem);
}
this.shiftItem = function () {
const shiftItem = this.qArray.shift();
this.displayQueue();
alert("Shift Item: " + shiftItem);
return shiftItem;
}
this.countItems = function () { }
this.displayQueue = function () {
document.getElementById("dQ").innerHTML = this.qArray;
}
}
let zardQueue = new OriginalQueue("Zard");
zardQueue.pushItem("A");
zardQueue.pushItem("B");
zardQueue.shiftItem();
</script>
</body>

</html>