Skip to content
Advertisements

JavaScript – Find The Largest And Smallest Number On An Array

CODEPEN:

Find The Largest And Smallest Number On An Array

Github: https://github.com/furkangulsen98/HTML-CSS-JAVASCRIPT/tree/master/Find%20The%20Largest%20And%20Smallest%20Number%20On%20An%20Array


HTML CODE:

<div class="container">
        <h2>Find the largest and smallest number on an array</h2>
        <input type="number" id="numbers" placeholder="Enter as many numbers as you want." />
        <button onclick="add()" id="add">ADD</button><br />
        <button onclick="small()">Smallest number</button>
        <button onclick="bigger()">Biggest number</button>
    </div>

CSS CODE:

 body, html {
            padding: 0;
            margin: 20px;
            background: #333;
            color: #e53f3f;
            font-family: Verdana;
            display: flex;
            height: 100vh;
            justify-content: center;
            align-items: center
        }
        input {
            width: 265px;
            display: inline-block;
            border: none;
            border-radius: 20px 0px 0px 20px;
            padding: 5px;
            padding-left: 10px;
            outline: none;
            font-family: Verdana;
        }
        #add {
            width: 50px;
            position: relative;
            display: inline-block;
            border: none;
            border-radius: 0px 20px 20px 0px;
            padding: 4px;
            margin-left: -5px;
            top: -1.5px;
            background: #e53f3f;
            color: #fff;
            font-size: 14px;
            outline: none;
        }
        button {
            width: 160px;
            padding: 5px;
            background: #e53f3f;
            color: #fff;
            border: none;
            margin-top: 10px;
            margin-left: 5px;
        }
        h2{
            font-size: 16px;
        }

JS CODE:

 let NumValues = [];

        function add() {
            let numbers = document.getElementById("numbers").value;
            NumValues.push(numbers);
            console.log(NumValues)
        }

        function small() {
            let min = Math.min.apply(Math, NumValues);
            alert(min)
        }

        function bigger() {
            let max = Math.max.apply(Math, NumValues);
            alert(max)
        }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: