-2

Entry level javascript that I'm trying to finish. Unfortunately my lack of skills won't let me. I know there's working prototypes of this program out but but I want to learn rather than just copy someone elses work. Thanks

<html>
    <head>
            <title> 1 </title>

        <style type="text/css">

        body {
            background-color:black;
            color:white;
        </style>
    </head>
    <body>
    <h1><b> Calculator </h1></b>

        <form id="timeForm">
            <table>
                <tr>
                    <td>Years:</td>
                    <td><input type="text" id="years" value="" size="10"></td>
                </tr>
                <tr>
                    <td>Months:</td>
                    <td><input type="text" id="months" value="" size="10"></td>
                </tr>
                <tr>
                    <td>Day:</td>
                    <td><input type="text" id="days" value="" size="10"></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><input type="button" id="button" value="Submit" onclick="handleInput();"></td>
                </tr>
            </table>
        </form>

        <p id="output"></p>

        <script language="Javascript">
        document.getElementById("output").innerHTML = output;
            }
        function handleInput() {
            var form = document.getElementById("timeForm");
            try {
                var strYears = form.years.value;
                var strMonths = form.months.value;
                var strDays = form.days.value;

                var intYears = parseInt(strYears);
                var intMonths = parseInt(strMonths);
                var intDays = parseInt(strDays);

                if (isNaN(intYears);
                    throw "Incorrect input. Years is not a number.";

                    if (intYears > 0 || intYears < 9999)
                    throw "Incorrect input. Years is out of expected range (0--9999).";

                    if (isNaN(intYears);
                    throw "Incorrect input. Months is not a number.";

                    if (isNaN(intMonths);
                    throw "Incorrect input. Months is not a number.";

                    if (intMonths > 0 || intMonths < 9999)
                    throw "Incorrect input. Months is out of expected range (0--9999).";

                    if (isNaN(intDays);
                    throw "Incorrect input. Days is not a number.";

                    if (intYears > 0 || intDays < 9999)
                    throw "Incorrect input. Months is out of expected range (0--9999).";

                    if (m == 1 | | m == 2) {
                    m = m + 12;
                    Y = Y - 1;

                    }

                    h = (q + Math.floor(13 * (m + 1) / 5) + Y + Math.floor(Y / 4)
                    - Math.floor(Y / 100) + Math.floor(Y / 400)) % 7;
                    {

                var output = "Weekday" = " + years + ":" + months + ":" + days + ".";

            catch (error) {
                document.getElementById("output").innerHTML = "ERROR: " + error;
            }
        }
        </script>
    </body>
</html>
brodude
  • 23
  • 5
  • 1
    What's your problem? where are you getting errors? – acostela Sep 20 '16 at 08:14
  • ` document.getElementById("output").innerHTML = output;` this is a bit weird. You declare output within handleInput but the previous statement runs first, so output does not exist (let alone it is in a different scope). Also there is an extra `}` after the first statement. – mkaran Sep 20 '16 at 08:18
  • I got a few errors but I think I managed to fix most of them thanks to the comments in this thread. The latest error is at line 84: var output = "Weekday" = " + years + ":" + months + ":" + days + "."; which is a little weird because I copied it directly from my teacher. Says "ReferenceError: invalid assignment left-hand side" – brodude Sep 20 '16 at 08:56
  • There's an extra quote there. Should be `"Weekday = "` – JJJ Sep 20 '16 at 09:00
  • I'm down to zero errors now but there is no output. When I type numbers in the boxes and calculate nothing happens. If I check the console I get "uncaught exception: Incorrect input. Years is not a number." . It should be typing it out on the website, not in the console. – brodude Sep 20 '16 at 09:10

2 Answers2

1

There is a whole bunch of syntax errors preventing the browser to execute your JavaScript.

If you want to see those, you can use your browser's developer tools to figure out where it choked.

geekonaut
  • 5,714
  • 2
  • 28
  • 30
0

The language attribute has been deprecated for a long time, as someone said in here link (and its true) so you don't have to put it there anymore, you should put the document.getElementById("output").innerHTML = output; under everything in your javascript script.

And you have a } there

    document.getElementById("output").innerHTML = output;
}

Whats up with that?

Community
  • 1
  • 1
Stephan
  • 69
  • 6
  • Please read [How do I format my code blocks?](http://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks) – Liam Sep 20 '16 at 08:58
  • Yes, my teacher said that but since he wrote it out I figured I should as well. I don't know what's up with that. I have very little idea what I'm actually doing despite quite some effort. – brodude Sep 20 '16 at 08:59