<Simple Calculator using HTML/CSS>
<form>
element is a container that contains different type of input elements.
in this project: I used <input>
and <button>
as a input elements inside the <form>
The elements that doesn't need closing tag is called Empty or Void elements.
<input type="button" value="1">
type="button"
will create a button element on the webpage value=" 1 "
defines that the number that is going to be the value of the button.
<input type="button" value="DE" onclick="display.value = display.value.toString().slice(0,-1)">
This particular part the code about the button DE(which deletes the lastly displayed number)
during the onclick display.value
will go through the following process to it's action done.
display.value.toString
= will take the value from the display and convert the value into string.
toString.slice()
= will returns the selected elements as a new array.
slice(start,end)
= start is the staring position we want for the new array/default is 0.
end is the end position/default is last element .
slice(0,-1)
\= so the starting will be not changing but the end position eliminates last element from the array and returns it. if the end is -2 then it eliminates the last two elements.
eval()
is an function property. it evaluate the strings and return the value. used this function for done the calculation part.
Live link:https://vaithegiv.github.io/Calculator
Source code: Check the link for the source code: https://github.com/VaithegiV/Calculator.git
Subscribe to my newsletter
Read articles from VaithegiV directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
VaithegiV
VaithegiV
Hi, I'm VaithegiV Frontend developer. B.Tech graduate with a passion for web development. Proficient in HTML, CSS, and JavaScript, I strive to create intuitive and visually appealing digital experiences. With expertise in Git and GitHub, I ensure efficient collaboration and version control in projects. My dedication to continuous learning drives me to stay updated with the latest trends in technology and design. I am eager to contribute my skills and creativity to innovative projects that push boundaries and deliver exceptional user experiences.