jeudi 25 août 2016

if else statement with result

I have a working form that calculates how long a product will last depending on the hours in a day it's used. I'm trying to add an alert to prevent users from inputting more than 24 hours a day and can't figure out how/where to put the if/else statements...

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script>
        if ("#hours" > 24){
         <script type='text/javascript'>alert('Nice try. ;)')
    </script>
    <script src="http://ift.tt/1pD5F0p"></script>
    <script src="http://ift.tt/1RY4jZJ"></script>
    <script>
        else {
            function calculate() {
            var hours = $("#hours").val();
            var totalBulbHours = 10000

            if (hours > 25) {
            text = 
            var result = totalBulbHours / (hours*365);
            $("#result").val(result.toFixed(0));
        }
        }
    </script>
</head>
<body>
    <div class="container">
        <form class="" role="form">
            <div class="form-group form-inline">
                <label for="hours">Hours Used per Day</label>
                <input type="number" class="form-control" id="hours" placeholder="">
            </div>
            <div class="form-group form-inline">
                <button type="button" class="btn btn-success" onclick="calculate()">Calculate</button>
            </div>
            <div class="form-group form-inline">
                <label for="result">Lamp Replacement After</label>
                <input type="text" class="form-control" id="result" placeholder="" readonly>
                <label for="result">Years</label>
            </div>
        </form>
    </div>
</body>

Aucun commentaire:

Enregistrer un commentaire