prompt alert 和 confirm 如何放在一起?

How to put prompt alert and confirm together?

如何把提示、提醒、确认放在一起? 我已经知道了,但是我想在提示和警告之后添加一个确认框。 有人可以帮忙吗?

<script>

var name = prompt('What is your name?')

alert('Your name is ' + name )

正如帕特里克在评论中建议的那样,您需要使用确认而不是警报,单击确认确定将为您提供值:true 即

<script>

var name = prompt('What is your name?');

var confirm = confirm('Your name is ' + name );

if(confirm === true){

 //Your code goes here
}
<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Try it</button>


<script>
function myFunction() {
    var name = prompt("Please enter your name", "XYZ");

    if (name != null) {
       alert('Your name is ' + name )


    }
}
</script>

</body>
</html>

它会询问你的名字,并在提示输入名字后进入警报。