Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
<link rel="stylesheet" href="style.css">
</head>
<body>
<input class="starter" id="input" placeholder="input"/>
<h2>output:</h2>
<select id="unitInput">
<option value="destination" selected="selected">Select Destination</option>
<option value="KL">KL</option>
<option value="bali">Bali</option>
</select>
<h1 class="toggle">Type "buy first/business/economy class" to buy the tickets.</h1>
<input class="starter" id="input" placeholder="Enter input"/>
<h2>Output:</h2>
<p class="starter" id="output"></p>
<script>
document.querySelector('#input').addEventListener('change', function(event){
var currentInput = event.target.value;
var result = inputHappened(currentInput);
display( result );
});

var display = function( data ){
var output = document.querySelector('#output');
output.innerText = data;
}
</script>
<script src="script.js"></script>
</body>
</html>
</html>
97 changes: 94 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,97 @@
console.log("hello script js");
document.querySelector('#input').addEventListener('change', function(event){
var currentInput = event.target.value;
var result = inputHappened(currentInput);
display( result );
});

var display = function( data ){
var output = document.querySelector('#output');
output.innerText = data;
}

let planeSeat = 10;
let economicSeats = 15;
let businessSeats = 6;
let firstClassSeats = 4;
let ecoPrice = 50;
let busPrice = 50;
let firstPrice = 50;


var inputHappened = function(currentInput){
console.log( currentInput );
return "WOW SOMETHING HAPPENED";
if(currentInput==="buy economy class"){
document.querySelector('#input').value="";
while (economicSeats>=0) {
if(economicSeats===1){
return "Economy seats sold out"
} else if(economicSeats===15){
ecoPrice = ecoPrice*1;
} else if(economicSeats>7){
ecoPrice = ecoPrice*1.05;
} else if(economicSeats>2){
ecoPrice = ecoPrice*1.03;
} else if(economicSeats===2){
ecoPrice = 91000;
}
economicSeats--;
return "Thank you. For Economy, the price is $"+ Math.ceil(ecoPrice) + " and there are still " + economicSeats + " seats left";
}
}else if(currentInput==="buy business class"){
document.querySelector('#input').value="";
while (businessSeats>=0) {
if(businessSeats===1){
return "Seats sold out"
} else if(businessSeats===6){
busPrice = busPrice*1;
} else if(businessSeats>4){
busPrice = busPrice*1.06;
} else if(businessSeats>2){
busPrice = busPrice*1.1;
} else if(businessSeats===2){
busPrice = 91000;
}
businessSeats--;
return "Thank you. For business class, the price is $"+ Math.ceil(busPrice) + " and there are still " + businessSeats + " seats left";
}
}else if(currentInput==="buy first class"){
document.querySelector('#input').value="";
while (firstClassSeats>=0) {
if(firstClassSeats===1){
return "Seats sold out"
} else if(firstClassSeats>2){
firstPrice = firstPrice*1.5;
} else if(firstClassSeats===2){
firstPrice = 91000;
}
firstClassSeats--;
return "Thank you. For first class, the price is $"+ Math.ceil(firstPrice) + " and there are still " + firstClassSeats + " seats left";
}
}
else{
return "Please type buy to buy the ticket."
}
};






// if(currentInput==="buy plane seat"){
// document.querySelector('#input').value="";
// while (planeSeat>=0) {
// if(planeSeat===1){
// return "Economy seats sold out"
// } else if(planeSeat===10){
// seatPrice = seatPrice*1;
// } else if(planeSeat>5){
// seatPrice = seatPrice*1.05;
// } else if(planeSeat>2){
// seatPrice = seatPrice*1.03;
// } else if(planeSeat===2){
// seatPrice = 91000;
// }
// planeSeat--;
// return "Thank you. The price is $"+ Math.ceil(seatPrice) + " and there are still " + planeSeat + " seats left";
// }
// }