Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Javascript Level 10 Lesson 8

 <!doctype html>
<html>
<head>
<title>JS Popup Boxes</title>
<style>
button {
background-color: #4535AA;
border: 0;
border-radius: 5px;
padding: 10px;
color: #FFF;
cursor: pointer;
}
#confirmBtn, #promptBtn {
display: none;
}
</style>
</head>
<body>
<button id="startBtn" onclick="start()">Start</button>
<button id="confirmBtn" onclick="sure()">Sure?</button>
<button id="promptBtn" onclick="welcome()">Your Name?</button>
<script>
function start() {
alert("Let's start the show...");
document.getElementById("confirmBtn").style.display = "block";
document.getElementById("startBtn").style.display = "none";
}

function sure() {
let result = ("Can we start?");
if(result)
{
document.getElementById("promptBtn").style.display = "block";
document.getElementById("confirmBtn").style.display = "none";
}
else {
document.getElementById("confirmBtn").style.display = "none";
document.getElementById("startBtn").style.display = "block";
}
}

function welcome() {
let name = ("What is your name?");
if(name !== null) {
document.write(`Welcome ${name} to Studytonight`);
}
else {
document.write("Oops! Cannot start without your name.");
}
startBtn.addEventListener('click', start);
confirmBtn.addEventListener('click', sure);
promptBtn.addEventListener('click', welcome);
}
</script>
</body>
</html>
by

1 Answer

kshitijrana14
Try this one
<!doctype html>
<html>
<head>
<title>JS Popup Boxes</title>
<style>
button {
background-color: #4535AA;
border: 0;
border-radius: 5px;
padding: 10px;
color: #FFF;
cursor: pointer;
}
#confirmBtn, #promptBtn {
display: none;
}
</style>
</head>
<body>
<button id="startBtn" onclick = "start()">Start</button>
<button id="confirmBtn" onclick = "sure()">Sure?</button>
<button id="promptBtn" onclick = "welcome()">Your Name?</button>
<script>
function start() {
alert("Let's start the show...");
document.getElementById("confirmBtn").style.display = "block";
document.getElementById("startBtn").style.display = "none";
}

function sure() {
let result = confirm("Can we start?");
if(result==true)
{
document.getElementById("promptBtn").style.display = "block";
document.getElementById("confirmBtn").style.display = "none";
}
else {
document.getElementById("confirmBtn").style.display = "none";
document.getElementById("startBtn").style.display = "block";
}
}

function welcome() {
let name = prompt("What is your name?");
if(name !== null) {
document.write(`Welcome ${name} to Studytonight`);
}
else {
document.write("Oops! Cannot start without your name.");
}

}
</script>
</body>
</html>

Login / Signup to Answer the Question.