Found 6710 Articles for Javascript

How to split JavaScript Number into individual digits?

Abhishek
Updated on 25-Nov-2022 08:22:16

4K+ Views

In this tutorial, we will learn how we can split a JavaScript number into individual digits. Sometimes, we need to split the number into individual digits to accomplish the task given to us like checking for the palindrome number. Let us discuss the methods to split numbers into digits. When the number is taken in the form of a number. When the number is taken in the form of a string. Let us discuss both of them individually with program examples. When the input is in form of a number If the input number is in the form ... Read More

How to deal with floating point number precision in JavaScript?

varma
Updated on 10-Jan-2020 07:29:46

896 Views

To handle floating point number precision in JavaScript, use the toPrecision() method. It helps to format a number to a length you can specify.ExampleLive Demo                    var num = 28.6754;          document.write(num.toPrecision(3));          document.write(""+num.toPrecision(2));          document.write(""+num.toPrecision(5));           Output28.7 29 28.675

How to convert a decimal number to roman using JavaScript?

Shubham Vora
Updated on 22-Aug-2022 09:25:10

801 Views

Roman numerals are a type of number system used to represent a fixed decimal number. Several letters from the Latin alphabet are used for the representation of roman numerals. In this tutorial, the user will learn how to convert a decimal number to roman using JavaScript. Seven symbols represent Roman numerals: I, V, X, L, C, D, and M. The values for symbols are given below. Syntax I is 1 V is 5 X is 10 L is 50 C is 100 D is 500 M is 1000 Using these seven symbols user can convert decimal numbers to roman. ... Read More

How I can change alert message text color using JavaScript?

Nitya Raut
Updated on 16-Jun-2020 13:24:05

2K+ Views

You can try to run the following code to change the alert message text color. To change the text color of the alert message, use the following custom alert box. We’re using JavaScript library, jQuery to achieve this and will change the alert message text color to “#FCD116” −ExampleLive Demo                                function functionAlert(msg, myYes) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);             confirmBox.find(".yes").unbind().click(function() {     ... Read More

How I can change the style of alert box using JavaScript?

Jennifer Nicholas
Updated on 25-Sep-2019 08:46:21

2K+ Views

You will not be able to change the style of a standard alert box in JavaScript. To change the style, use the following custom alert box. We’re using JavaScript library, jQuery to achive this.ExampleLive Demo                                function functionAlert(msg, myYes) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);             confirmBox.find(".yes").unbind().click(function() {                confirmBox.hide();             });     ... Read More

How to count the number of occurrences of a character in a string in JavaScript?

varun
Updated on 17-Jun-2020 06:39:27

799 Views

To count the number of occurrences of a character in a string, try to run the following code −ExampleLive Demo                    function displayCount() {             setTimeout(function() {                var str = document.getElementById('str1').value;                var letter = document.getElementById('letter1').value;                letter = letter[letter.length-1];                var lCount;                for (var i = lCount = 0; i < str.length; lCount += (str[i++] == letter));                document.querySelector('p').innerText = lCount;                return lCount;             }, 50);          }             Enter String:       Enter Letter:       Click for Result       result=    

How do I display image in alert/confirm box in JavaScript?

Shubham Vora
Updated on 22-Jul-2022 12:41:15

5K+ Views

In this tutorial, we will learn to display the image in the alert or confirm box in JavaScript. The alert() is the JavaScript method that displays the alert or confirms box on the top center of the screen when you invoke it.As a programmer and user, you have seen on many websites that they ask you for confirmation in the dialog box before you delete any precious thing in your user's account. Also, the alert box can be helpful to show some information when a user comes into the web page or a message.So, the default alert box can have only ... Read More

How to show image in alert box using JavaScript?

Nancy Den
Updated on 16-Jun-2020 13:14:55

2K+ Views

To show an image in alert box, try to run the following code. Here, an alert image is added to the custom alert box −ExampleLive Demo                                function functionAlert(msg, myYes) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);             confirmBox.find(".yes").unbind().click(function() {                confirmBox.hide();             });             confirmBox.find(".yes").click(myYes);         ... Read More

What is the best way to initialize a JavaScript number?

Prabhas
Updated on 17-Jun-2020 06:38:06

736 Views

The best way to initialize a number in JavaScript is to initialize variables while declaring them. Through this, you can easily avoid undefined values.ExampleYou can try to run the following code to initialize a number −Live Demo                    var deptNum = 20, id = 005;          document.write("Department number: "+deptNum);          

How I can replace a JavaScript alert pop up with a fancy alert box?

Daniol Thomas
Updated on 16-Jun-2020 13:10:14

1K+ Views

To design a custom JavaScript alert box, try to run the following code. The code uses a JavaScript library jQuery and CSS to create a fancy alert box different from the standard JavaScript alert box −ExampleLive Demo                                function functionAlert(msg, myYes) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);             confirmBox.find(".yes").unbind().click(function() {                confirmBox.hide();             }); ... Read More

Advertisements