Cuộc đua xe
Mục tiêu của mã này là để có được đầu ra bằng cách sử dụng với các lớp.Classes.
đầu vào
dòng đầu vào đầu tiên chứa một chuỗi playernameplayerName
Dòng đầu vào thứ hai chứa một số nitronitro
dòng thứ ba của đầu vào chứa tốc độ sốspeed
đầu ra
Đầu ra chứa nhiều dòng với các văn bản thích hợp
đầu vào1
Alyssa
100
1
output1
Cuộc đua đã bắt đầu
Tốc độ 50; Nitro 50
tốc độ 70; Nitro 60
Alyssa là người chiến thắng
Tốc độ 0; Nitro 60
chức năng readline [] {
& nbsp; return inputString [currentLine ++];
}
& nbsp; // Tạo xe siêu hạng và xe phụ của bạn ở đây
hàm main [] {
& nbsp; const playername = readline [];
& nbsp; const nitro = json.parse [readline []];
& nbsp; const Speed = json.parse [readline []];
& nbsp; const car1 = xe mới [playername, nitro, tốc độ];
console.log[car1.startRace[]];
& nbsp; car1.nitroboost [];
& nbsp; console.log [`Speed $ {car1.speed}; nitro $ {car1.nitro}`];
car1.accelerate[];
& nbsp; console.log [`Speed $ {car1.speed}; nitro $ {car1.nitro}`];
console.log[car1.endRace[]];
car1.applyBreak[];
& nbsp; console.log [`Speed $ {car1.speed}; nitro $ {car1.nitro}`];
}
Trả lời cho câu hỏi #295727 trong Ứng dụng web HTML/JavaScript cho Chethan
Mục tiêu của mã này là nhanh chóng để lên khỏi mặt đất với các lớp học.
Cho playername, nitro và tốc độ là đầu vào viết một cuộc đua siêu lớp với tài sản và phương pháp
đầu vào
- dòng đầu vào đầu tiên chứa dưới dạng chuỗi playername
- dòng đầu vào thứ hai chứa dưới dạng chuỗi nitro
- dòng thứ ba của đầu vào chứa dưới dạng tốc độ chuỗi
đầu ra
- Đầu ra bao gồm nhiều dòng với các văn bản thích hợp
Mẫu đầu vào1
Alyssa
100
đầu ra mẫu1
Cuộc đua đã bắt đầu
tốc độ 50; Nitro 50
tốc độ 70; Nitro 60
Alyssa là người chiến thắng
Tốc độ 0; Nitro 60
Mẫu đầu vào2
Joel
100
100
đầu ra mẫu2
Cuộc đua đã bắt đầu
tốc độ 50; Nitro 50
tốc độ 70; Nitro 60
Alyssa là người chiến thắng
Tốc độ 0; Nitro 60
class Race {
constructor[playerName, nitro, speed] {
this.playerName = playerName;
this.nitro = nitro;
this.speed = speed;
}
boostSpeed[] {
this.speed = this.speed + 50;
this.nitro = this.nitro - 50;
}
ride[] {
this.speed = this.speed + 20;
this.nitro = this.nitro + 10;
}
stopRace[] {
this.speed = 0;
}
speedAndNitroMessage[] {
console.log[`speed ${this.speed} nitro ${this.nitro}`]
}
winMessage [] {
console.log[`${this.playerName} is the winner`]
}
startRace[] {
console.log['Race has started']
this.boostSpeed[]
this.speedAndNitroMessage[]
this.ride[]
this.speedAndNitroMessage[]
this.winMessage[]
this.stopRace[]
this.speedAndNitroMessage[]
}
}
const race = new Race['Alina', 100, 0];
race.startRace[]
Mẫu đầu vào2 Joel đầu ra mẫu2 tốc độ 150; Nitro 50 tốc độ 170; Nitro 60 Joel là người chiến thắng //www.codersarts.com/contact
Click Here to Start
*{
margin: 0;
padding: 0;
}
/* Track Styling and positioning */
.track {
background-color: blue;
position: absolute;
width: 100vw;
height: 100vh;
}
#car {
background-image: url['./Images/car1.png'];
background-repeat: no-repeat;
background-size: cover;
width: 35rem;
height: 15.699rem;
position: absolute;
bottom: 50px;
margin-top: 500px;
left: 0;
}
#car2 {
background-image: url['./Images/car2.png'];
background-color: aliceblue;
background-repeat: no-repeat;
background-size: cover;
width: 35rem;
height: 15.699rem;
position: absolute;
top: 20%;
left: 0;
}
.line{
background-color: black;
width: .5%;
margin-left: 1200px;
height: 100vh;
}
@keyframes trackanimation {
100% {
transform: translate[-500vw];
}
}
const car = document.getElementById['car'];
var computedStyle=window.getComputedStyle[car]
const car2=document.getElementById['car2']
var computedStyle2=window.getComputedStyle[car2]
car2.style.left="0px"
var count=0;
var count2=0;
var x=0;
var y;
function start1[]{
y=setInterval[
function start[]{
let a=Math.floor[Math.random[] * 100];
let b=Math.floor[Math.random[] * 100];
count+=a;
count2+=b;
car2.style.left=`${count}px`;
car.style.left=`${count2}px`;
if[count>=700 || count2>=700]
{
clearInterval[y];
stop[];
}
},1000]
}
function stop[]{
car2.style.left=`${count}px`;
car.style.left=`${count2}px`;
if[count>=700]
{
alert["Car 1 has won"];
}
else if[count2>=700]
{
alert["Car 2 has won"];
}
}