Internship Journal Day #1
Hello Folks
This summer I get to intern in Crisp Analytics. I have two seniors of mine there - AP Sir and Punit Sir.
The day started with the introduction to other people there. Then they told me an dmy fellow interns, Abhishek and Gaurav, about the technologies they use and giving the brief ideas of their projects.
Linux basic commands, introduction to version control, HTML and CSS; all these were covered. I was already familiar with all these, so it went very smoothly. Then it was lunch time. I had not got any food with me, so Shoaib Sir took me to Haldirams and we had lunch together. He is a very friendly guy and I got to know that he was alumni of our college, '97 batch.
After that we were assigned to develop a calculator using HTML, CSS and JavaScript (without using JQuery).
I thought it to be pretty simple at first. But it wasn't as I started. Coding a calculator in console is very easy, you tell user to give input and what but GUI based calculator gives user independence of pressing any key anytime.
So, first I started with the layout. Due to two big buttons, I used table for the layout of buttons. But then Punit Sir reminded me 'using table is bad practice'. And indeed it was, it was not flexible to give margins to table cells (td) and they were nit behaving well with float and display:block or display:inline-block.
Then, I used li for the buttons then again a problem arose. When I made the two big buttons, the last three buttons went down giving abnormal space. I discussed with AP Sir and decided to make two separate divs for below two lines. But then I found the smaller work around, to translate the bottom three buttons to upwards.
Then I began working on logic. Using JavaScript without JQuery is really troublesome. I did not like the idea to put onclick in each li tag, so I discussed with Punit Sir and he told me to use addEventListener for click event for li items.
I first tried to develop the basic calculations like addition, subtraction, division and multiplication of two numbers. For that, I wrote a function on li click which takes up the innerHTML of the element and then display that in the answerbox. First number was kept on scanning until there some operator key is not pressed after that second number starts getting scanned.
Then I go for one operand functions like, square root and logarithm. So, whenever they are pressed, number string is parsed into integer and then answer is displayed after applying the corresponding function. If, before applying log or root, there is a calculation to be pending (like 2+3) then the answer is calculated on the result of pending calculation.
Similarly, I modified the former function to accept chaining of calculation (like 2+3-1). After that, I modified equal function such that it does not reset the calculation after being pressed, instead starts a new calculation if number is pressed or continue with the previous (chaining) if operator is pressed.
Then, we gave presentation on what we did and how we did. There were some bugs like after doing 1/0, it was giving infinity but when I chained the calculation by + 1, it was giving answer 2. I got to know about magic numbers (0 and 1). They must not be used if they have other meaning than true and false. Some more suggestions on coding styles were given by the people there.
So, it was a really good session. Using JQuery is very easy and I always used to think how could it be developed because I didn't know about the native methods like addEventListener. The motive of Punit Sir got fulfilled. Coding in JavaScript strengthened my fundamentals about the language.
Let's start with the 2nd day. :)