Nithish-Kumar-K / Delta-Inductions

0 stars 0 forks source link

Input's value is a String, not a a Number #1

Open thakkarparth007 opened 8 years ago

thakkarparth007 commented 8 years ago

In timerscript.js you are having these:

    year=document.getElementById("Year").value;
    month=document.getElementById("Month").value - 1 ; //java script months starting is 0
    day=document.getElementById("Day").value;
    hour=document.getElementById("Hour").value;
    minute=document.getElementById("Minute").value;
    second=document.getElementById("Second").value;

Each of these variables is a String and not Number. If you knew that, then fine. If you didn't be warned: This will cause you a lot of headache later if you're not careful. This code works though because of the way JS works, however I'd like to warn you against such implicit type casting. Example:

If you do '3'+'1', you're adding a String and a String and it does String concatenation, which is fine. But if you do '3' + 1, it converts 1 (a Number) to a String and returns '31'. But, here's where things start getting funny: '3' - 1 converts the 3 to an integer and you get 2. Sensible in some way, but very dangerous if you're not careful.

Nithish-Kumar-K commented 8 years ago

When I started using input box I didn't know about what you said. But later I found it. Thank u for telling me

On Sat, May 28, 2016 at 4:04 PM, Parth Thakkar notifications@github.com wrote:

In timerscript.js you are having these:

year=document.getElementById("Year").value;
month=document.getElementById("Month").value - 1 ; //java script months starting is 0
day=document.getElementById("Day").value;
hour=document.getElementById("Hour").value;
minute=document.getElementById("Minute").value;
second=document.getElementById("Second").value;

Each of these variables is a String and not Number. If you knew that, then fine. If you didn't be warned: This will cause you a lot of headache later if you're not careful. This code works though because of the way JS works, however I'd like to warn you against such implicit type casting. Example:

If you do '3'+'1', you're adding a String and a String and it does String concatenation, which is fine. But if you do '3' + 1, it converts 1 (a Number) to a String and returns '31'. But, here's where things start getting funny: '3' - 1 converts the 3 to an integer and you get 2. Sensible in some way, but very dangerous if you're not careful.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Nithish-Kumar-K/Delta-Inductions/issues/1, or mute the thread https://github.com/notifications/unsubscribe/ARvWrJoVzyQUrjnx64FNL9p3RzBWGrmSks5qGBongaJpZM4IpC_X .

Nithish-Kumar-K commented 8 years ago

I have fixed the start button and the date input problems.

Nithish-Kumar-K commented 8 years ago

Also please tell me if I should change my indentation and my comments or variable names

thakkarparth007 commented 8 years ago

Use http://www.jslint.com/ this to check code styling of your JS code. Don't follow everything that's said there, because certain things aren't really important, but most of the rules described there are useful. Indentation for html will be similar.