DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Geekyoda
Geekyoda

Posted on

UI with one input field that accepts only numbers in Javascript

Create a simple UI with one input field that accepts only numbers.

If the user types negative numbers, show "enter a positive value".
If the user types an even number, show the next 3 even numbers.
If the user types an odd number, show the next 3 odd numbers.

Top comments (2)

Collapse
 
nileshrawatau45 profile image
Nilesh Rawat

so how to do it can you answer?

here is my code

function fun(){
var a = document.getElementById("numvalid")

if(a < 1){
   return(document.getElementById("msg").innerHTML= "enter the positive value") 


}
else{
    return 
}
Enter fullscreen mode Exit fullscreen mode

}

console.log(fun())

Collapse
 
aniketmishra profile image
Aniket Mishra

Solution

This post blew up on DEV in 2020:

js visualized

πŸš€βš™οΈ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! πŸ₯³

Happy coding!