JavaScript Alert Messages || JavaScript Message Box

JavaScript

Whenever a Developer wants to show JavaScript alert Messages to user,he or she write the respective message in alert() function and call it whenever he or she wants. Alert is JavaScript built-in function use to popup message box in the window web browser.

The Alert Message parameter can be a String ,Number or Boolean value.

Example #1:

<script>
alert("Your Message !!!");
</script>

Output:

Javascript

Example #2:

<script>
alert(100+100);
</script>

Output:

Javascript

Example #3:

 <script>
alert(true);
</script>

Output:

Javascript

We can call the JavaScript alert Messages function whenever using a button on website, onclick function embedded in the button will call the function of alert Message.

Example #4:

<html> 
<body> 
<button onclick="alert_Messege('The Message')">Alert Message</button>
<script> 
function alert_Messege(message){
    alert(message);
}
</script>
</body>
</html>

Output:

Javascript

Confirm Box:

The Confirm Box ask the user whether OK or CANCEL a specific condition or question which is asked.The popup method of this message is same as of alert but confirm() function is to call and it will return Boolean value as true or false.

Example #5:

<script> 
if(confirm("Do we remember your password?")){
console.log("Remember")
}else{
console.log("Not Remember")
} 
</script>

Output:

Javascript

Prompt Box:

Prompt Box is use to take the input from the user. The prompt function return the value insert by the user through the window of the web browser.

Example #6:

<script>
var number=prompt("Enter any number")
if(number>=10){
console.log("The Number is greater than 10")
}else{
console.log("The Number is less than 10")
} 
</script>

Output:

Javascript

As we see in the above example that a Message is popup in the window screen of browser and user entered “10” in the input box. The value will be return in form of integer because 10 is integer. If the user enter the string value like “Hello World” than it will return as string and the else block of above example will always run for string.  

 

 For more Examples Related CSS,html and Java Script Visit on Coding Academics

For Web,Java and Assembly language related Semester Projects please Visit on Programming Zone.

Leave a Reply

Your email address will not be published. Required fields are marked *