• Exclusive

    Hey Guest, unlock an instant 10% bonus discount when you upgrade via the Crypoverse gateway.

Random Name Generator Javascript (1 Viewer)

Currently reading:
 Random Name Generator Javascript (1 Viewer)

Recently searched:

Engfree

Member
LV
0
Joined
Aug 20, 2023
Threads
10
Likes
0
Awards
2
Credits
819©
Cash
0$
In this post, we learn to generate random names using javascript. Here we have the first and last names array. Using the getRandomInt() method we select one name from each array and concatenate them into a full name
Code:
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Random Name Generator Javascript</title>
</head>
<body style="background-color: lightcyan;">

  <input id="clickMe" type="button" value="Generate Random Name" onclick="generateName();" />
 
  <h2 id="random_name"></h2>
 

  <script>
    function capFirst(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
    }

    function getRandomInt(min, max) {
        return Math.floor(Math.random() * (max - min)) + min;
    }

    function generateName(){
      var first_name = ["abandoned","able","absolute","adorable"];

      var last_name = ["people","history","way","art","world"];

      var name = capFirst(first_name[getRandomInt(0, first_name.length + 1)]) + ' ' + capFirst(last_name[getRandomInt(0, last_name.length + 1)]);
        document.getElementById("random_name").innerHTML = name;
    }
  </script>

</body>
</html>
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips
Recently searched:

Similar threads

Users who are viewing this thread

Top Bottom