Input Element and Math Functions

 

1. Math Functions

1.1 Math.random()

The

Math.random()
function returns a random number (float value) in range 0 to less than 1 (
0 <= randomNumber < 1
).

console.log(Math.random());
JAVASCRIPT

1.2 Math.ceil()

The

Math.ceil()
function always rounds a number up to the next largest integer.

console.log(Math.ceil(95.906698007537561)); // 96
JAVASCRIPT

Try running the code multiple times and observe the output in the console.

2. HTML Elements

2.1 HTML Input Element

The HTML

input

element creates interactive controls to accept the data from the user.

There are different types of inputs.

  • Text
  • Password
  • Radio
  • Date
  • Checkbox

2.1.1 Text Input

<input type="text" />
HTML
Note
Default type for the HTML 
input
 element is 
text
.

2.1.2 Password Input

It provides a way for the user to enter a password securely.

<input type="password" />
HTML

3. DOM Properties

3.1 Value

We can use the

value

property to get the value of the HTML

input

Element.

document.getElementById("inputElement").value;
JAVASCRIPT

Try out giving the different input values and check the output in the below Code Playground.


4. Comparison Operator

4.1 Loose equal to vs Strict equal to (
==
 vs 
===
)

Loose equal to (

==

): Loose equality compares two values for equality but doesn’t compare types of values. Strict equal to (

===

): Strict equality compares two values for equality including types of values.

console.log(2 == '2'); // true
console.log(2 === '2'); // false
JAVASCRIPT

Try out giving the different input values and check the output in the below Code Playground.

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

Contact Form