Jump to content

How to make a calculator


Pradeep6868

1 post in this topic

Recommended Posts

Hi earthling,

In this series, we are going to be making a simple calculator with basic HTML, CSS and JavaScript. Our calculator will only able to perform basic math operations: addition, subtraction, multiplication and division. To better understand this tutorial you would need to have a little knowledge of HTML and CSS.

If you don’t already know them, no need to worry. I simplified this tutorial as best as I could, so you would survive :)

So what exactly do we need to build this?

As you might have already guessed, we would need to create “buttons” for inputting values and a screen for displaying these values.

Well, basically, that’s it!

But in fancier terms, these are the components we need:

· A display area for displaying operators, operands and solutions.

· Buttons for inputting values to the display screen

Visually, a calculator is a table enclosed in a container. And as you should already know tables are made of rows and columns with cells to contain table data.

1*wiLL9NX7GoGzXxSQr6nOGQ.png

Now you get the concepts, let’s get started!

This is the basic format for HTML documents.

<html>

 <head></head>

 <body>

    <! -- Content -- >

 </body>

</html>

If you don’t already understand how to deploy HTML scripts you should take a look at this short tutorial.

The visible part of a webpage goes into the <body> </body> tag.

Before I go any further, it’s essential you understand certain HTML terminologies (fancy words) such as tags, attributes and elements.

Tags: Tags are basic labels that define and separate parts of your markup into elements. They are comprised of a keyword surrounded by angle brackets <>. Content goes between two tags and the closing one is prefixed with a slash (Note: there are some self-closing HTML tags, like image tags).

<!-- This is an opening and closing paragraph tag -->

<p></p>

Attributes: A property of an HTML element used to provide additional instructions to a given HTML tag. The attribute is specified in the opening HTML tag.

<!-- Here, the class is the attribute -->

<p class=""></p>

Elements: An HTML element usually consists of a opening tag and end tag, with the content inserted in between.

<!-- The element spans from the opening tag to the closing tag -->

<p class="paragraph">This is a paragraph.</p>

Okay! Enough with the basics. Let’s dance.

The first thing that goes into our HTML body is the form element <form></form>. After it has been created, an attribute titled “name”, with the value, calculator, should then be added to the opening form tag.

<html>

 <head></head>

 <body>

    <form name=”calculator”>

    </form>

 </body>

</html>

 

The form element is to serve as a wrapper (container) for the table which will contain the main calculator components.

Okay, what’s next?

Next, we need to create the table.

So what’s a table? No, not the furniture!

Excuse my poor attempt at making a joke.

HTML tables allow web designers to arrange data like text, images, links, other tables, etc. into rows and columns of cells. They are created using the <table> tag in which the <tr> tag is used to create table rows and <td> is used to create data cells.

Row is the horizontal and column is the vertical one, by the way.

Enough talk, let’s code now.

Inside the opening and closing <form> tag, we need to create a table element.

<html>

 <head></head>

 <body>

    <form name=”calculator”>

       <table>

       </table>

    </form>

 </body>

</html>

That was a breeze, right? Great, but it sort of gets complicated now, so you might want to turn off your twitter notification and set your eyes on the screen!

F - O - C - U - S

Inside the <table> tag, we need to define the table rows <tr> which is basically going to be the horizontal section of the calculator and the table data <td> (table column cell) which is to contain the calculator display and buttons.
1*QOjYBDqPjdUrd7zxd7i4hg.jpeg

The first horizontal section of our calculator is to contain the display screen.

The second horizontal section is to contain the first set of buttons. The first one is 1, the second one is 2, the third is 3, and the fourth is the + plus sign.

The third horizontal section also contains buttons! The first one is 4, the second one is 5, the third is 6, and the fourth is the - minus sign.

Other horizontal sections? Well, they contain… more buttons!

Let’s code:

<html>

 <head></head>

 <body>

    <form name=”calculator”>

       <table>

         

          <tr>

             <td>

                <input type="text" name="display" id="display" disabled>

             </td>

          </tr>

       </table>

    </form>

 </body>

</html>

That’s for the first horizontal section, which contains the display area of the calculator.

Hey! No need to scroll up. You are right, I haven’t talked about the inputelement and every other thing in between.

So what is an input element?

An input element is a form element — the most important one at that. The input element can be displayed in several ways, depending on the typeattribute. If you are following closely, I bet you are wondering why our type attribute type = "" is set to text and not number.

Here’s your answer, a calculator not only displays numbers but it also displays operators. So the type attribute has to be set to text to accommodate both numbers and symbols (operators).

For this tutorial, I would not talk about what the id and class attribute actually are and how they used.

Finally, for the first horizontal section, there is the disabled attribute. The disabled attribute is a boolean attribute. When present, it specifies that the <input> element should be disabled. A disabled input element is unusable and un-clickable. The point of making our input element disabled, is to make the calculator button the only way users can send texts to the display. We don’t want users typing random alphabets in the display area now, do we?

Now, the second horizontal section.

Here, there are four table cell columns! So we have to use the table data <td>tag four times to define them.

<html>

 <head></head>

 <body>

    <form name=”calculator”>

       <table>

         

          <tr>

            <td>

               <input type="text" name="display" id="display" disabled>

            </td>

         </tr>

         <tr>

            <td><input type=”button” name=”one” value=”1" onclick=”calculator.display.value += ‘1’”></td>

            <td><input type=”button” name=”two” value=”2" onclick=”calculator.display.value += ‘2’”></td>

            <td><input type=”button” name=”three” value=”3" onclick=”calculator.display.value += ‘3’”></td>

            <td><input type=”button” class=”operator” name=”plus” value=”+” onclick=”calculator.display.value += ‘+’”></td>

         </tr>

      </table>

    </form>

 </body>

</html>

The first <td> tag contains the number 1, the second one is for the number 2 and so on. To make the input element a button, the type attribute should be set to button.

Whatever goes into the value attribute value = "" is what would be display on the button.

Now the onclick attribute!

If you have come this far, you should grab a bottle of beer. You deserve it.

The onclick attribute determines what is run when a click occurs. It causes a block of JavaScript code to run.

For this tutorial, I would not go deep into the use of the onclick attribute.

Essentially, the code contained in the onclick attribute is simply telling the web browser to display whatever value the button holds when it is clicked.

The actual value of the input is only modified with the += (append to). If the current calculator input is 5 + and 10 is clicked, 10 will be appended: it then becomes 5 + 10, which is 15. Without the “append to” symbol, the number 10 will override 5. And only 10 will be displayed on the calculator screen.

The content for the second horizontal section should be repeated for the third and the fourth row. All that would be changed is the input value.

But things are going to be a little different for the fifth row.

Why?

The equals to function!

The onclick attribute onclick = "" of the equals to function would contain something a little different from the rest.

<td>

<input type=”button” name=”doit” value=”=”            onclick=”calculator.display.value = eval(calculator.display.value)”></td>

What eval(calculator.display.value) does is to interpret the value of the input as Javascript. So when there is a 4 + 6 in the input, it’ll be evaluated as Javascript and return 10.

Yippee!

That wasn’t so hard, now was it?

When all the individual components are pieced together, we have a fully functional (not so attractive) calculator.

Link to comment
https://iosgods.com/topic/69140-how-to-make-a-calculator/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Our picks

    • CarX Street v1.8.0 +6 Cheats
      Modded/Hacked App: CarX Street By KAR IKS TEKHNOLODZHIS, OOO
      Bundle ID: com.carxtech.sr
      iTunes Store Link: https://apps.apple.com/us/app/carx-street/id1458863319?uo=4


      Hack Features:
      - Unlimited Money [ Buy Fuel ]
      - Unlimited Gold [ Change Nickname ]
      - Unlimited Nitro
      - Freeze Fuel
      - 1 Million XP [ add some ] - risky
      - No Traffic

      Note: You can change nickname while having 0 gold.
      Note 2: You may be banned for abusing the hack. Please do not use high currency values. If you get blocked, deleting the game and installing it again should allow you to use guest account.


      Non-Jailbroken & No Jailbreak required hack(s): https://iosgods.com/topic/162958-carx-street-v100-2-cheats-for-jailed-idevices


      iOS Hack Download Link: https://iosgods.com/topic/162931-carx-street-v111-6-cheats/
        • Agree
        • Thanks
        • Winner
        • Like
      • 2,823 replies
    • Cafeland - World Kitchen Cheats v2.37.5 +1
      Modded/Hacked App: Cafeland - World Kitchen by Gamegos Internet Teknolojileri Ltd Sti.
      Bundle ID: com.gamegos.mobile.cafeland
      iTunes Store Link: https://apps.apple.com/us/app/cafeland-world-kitchen/id1147665432?uo=4&at=1010lce4



      Hack Features:
      - Freeze Currencies


      iOS Hack Download Link: https://iosgods.com/topic/100701-arm64-cafeland-world-kitchen-cheats-v2023-1/
        • Agree
      • 392 replies
    • Gran Saga Idle:KNIGHTSxKNIGHTS Cheats v1.22.3 +2
      Modded/Hacked App: Gran Saga Idle:KNIGHTSxKNIGHTS By Kakao Games Corp.
      Bundle ID: com.piedpixels.gransagaidle
      iTunes Store Link: https://apps.apple.com/us/app/gran-saga-idle-knightsxknights/id6482985104?uo=4


      Hack Features:
      - Multiply Attack
      - Multiply Defense


      iOS Hack Download Link: https://iosgods.com/topic/182761-gran-saga-idleknightsxknights-cheats-v101-2/
      • 240 replies
    • Dragon City - Breed & Battle! Cheats v24.12.6 +4 [ Always Your Turn / One Hit Kill ]
      Modded/Hacked App: Dragon City - Breed & Battle! By Socialpoint
      Bundle ID: es.socialpoint.dragoncity
      iTunes Store Link: https://apps.apple.com/us/app/dragon-city-breed-battle/id561941526?uo=4


      Hack Features:
      - One Hit Kill
      - God Mode 
      - Auto-Battle Unlocked

      This hack is using the new iOSGods Auto Updater. The hack will automatically update itself to the current app version you have installed on your iDevice.
      Note:
      Everything is linked with enemies, please use it carefully

      This hack works on the latest x64 or ARM64 & ARM64e iDevices: iPhone 5s, 6, 6 Plus, 6s, 6s Plus, 7, 7 Plus, 8, 8 Plus, X, Xr, Xs, Xs Max, 11, 11 Pro, 11 Pro Max, 12, 12 Pro, 12 Pro Max, 12 Mini, 13, 13 Pro, 13 Pro Max, 13 Mini, 14, 14 Plus, 14 Pro, 14 Pro Max, SE, iPod Touch 6G, 7G, iPad Air, Air 2, iPad Pro & iPad Mini 2, 3, 4, 5, 6 and later.


      iOS Hack Download Link: https://iosgods.com/topic/129371-dragon-city-mobile-cheats-auto-updating-3-god-mode-one-hit-kill/
      • 2,112 replies
    • My Hot Pot Story Cheats v4.3.1 +1
      Modded/Hacked App: My Hotpot Story By 冲 于
      Bundle ID: com.lxqd.hotpotiver
      iTunes Store Link: https://apps.apple.com/us/app/my-hotpot-story/id1623328997?uo=4


      Hack Features:
      - Infinite Currencies


      Non-Jailbroken & No Jailbreak required hack(s): https://iosgods.com/topic/166067-my-hotpot-story-v145-jailed-cheats-1/


      iOS Hack Download Link: https://iosgods.com/topic/166065-my-hotpot-story-cheats-all-versions-1/
      • 127 replies
    • Shadow Fight 3 Cheats v1.40.2 +4
      Modded/Hacked App: Shadow Fight 3 by Nekki Limited
      Bundle ID: com.nekki.shadowfight3
      iTunes Store Link: https://apps.apple.com/us/app/shadow-fight-3/id964827011?uo=4&at=1010lce4



      Hack Features:
      - Freeze Enemies
      - Auto Win


      Hack Download Link: https://iosgods.com/topic/81752-arm64-shadow-fight-3-cheats-v1204-2/
        • Agree
        • Haha
        • Like
      • 3,680 replies
    • Hollywood Story: Fashion Star Cheats v12.9 +4
      Modded/Hacked App: Hollywood Story By nanobitsoftware.com
      Bundle ID: com.nanobitsoftware.hollywoodstory
      iTunes Store Link: https://itunes.apple.com/us/app/hollywood-story/id876656488?mt=8&uo=4&at=1010lce4


      Hack Features:
      - Infinite Cash
      - Infinite Gems
      - Infinite Energy
      - Infinite Stars Point
       


      Non-Jailbroken & No Jailbreak required hack(s): https://iosgods.com/forum/79-no-jailbreak-section/
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Like
      • 762 replies
    • (Kyoutou Kotoba RPG: Kotodaman) コトダマン-共闘ことばRPG v7.3.5 +2 Jailed Cheats
      Modded/Hacked App: コトダマン-共闘ことばRPG By XFLAG, Inc.
      Bundle ID: com.sega.Kotodaman
      iTunes Store Link: https://apps.apple.com/jp/app/%E3%82%B3%E3%83%88%E3%83%80%E3%83%9E%E3%83%B3-%E5%85%B1%E9%97%98%E3%81%93%E3%81%A8%E3%81%B0rpg/id1298368256?uo=4


      Mod Requirements:
      - Non-Jailbroken/Jailed or Jailbroken iPhone/iPad/iPod Touch.
      - Sideloadly / Cydia Impactor or alternatives.
      - A Computer Running Windows/macOS/Linux with iTunes installed.


      Hack Features:
      - Damage Multiplier
      - Defense Multiplier


      Jailbreak required hack(s): 


      iOS Hack Download IPA Link:

      Hidden Content

      Download via the iOSGods App








      PC Installation Instructions:
      STEP 1: If necessary, uninstall the app if you have it installed on your iDevice. Some hacked IPAs will install as a duplicate app. Make sure to back it up so you don't lose your progress.
      STEP 2: Download the pre-hacked .IPA file from the link above to your computer. To download from the iOSGods App, see this tutorial topic.
      STEP 3: Download Sideloadly and install it on your PC.
      STEP 4: Open/Run Sideloadly on your computer, connect your iOS Device, and wait until your device name shows up.
      STEP 5: Once your iDevice appears, drag the modded .IPA file you downloaded and drop it inside the Sideloadly application.
      STEP 6: You will now have to enter your iTunes/Apple ID email login, press "Start" & then you will be asked to enter your password. Go ahead and enter the required information.
      STEP 7: Wait for Sideloadly to finish sideloading/installing the hacked IPA. If there are issues during installation, please read the note below.
      STEP 8: Once the installation is complete and you see the app on your Home Screen, you will need to go to Settings -> General -> Profiles/VPN & Device Management. Once there, tap on the email you entered from step 6, and then tap on 'Trust [email protected]'.
      STEP 9: Now go to your Home Screen and open the newly installed app and everything should work fine. You may need to follow further per app instructions inside the hack's popup in-game.

      NOTE: iOS/iPadOS 16 and later, you must enable Developer Mode. For free Apple Developer accounts, you will need to repeat this process every 7 days. Jailbroken iDevices can also use Sideloadly/Filza/IPA Installer to normally install the IPA with AppSync. If you have any questions or problems, read our Sideloadly FAQ section of the topic and if you don't find a solution, please post your issue down below and we'll do our best to help! If the hack does work for you, post your feedback below and help out other fellow members that are encountering issues.


      Credits:
      - AlyssaX64


      Cheat Video/Screenshots:

      N/A
      • 22 replies
    • (Kyoutou Kotoba RPG: Kotodaman) コトダマン-共闘ことばRPG v7.3.5 +2 Cheats
      Modded/Hacked App: コトダマン-共闘ことばRPG (Kyoutou Kotoba RPG: Kotodaman) By XFLAG, Inc.
      Bundle ID: com.sega.Kotodaman
      iTunes Store Link: https://apps.apple.com/jp/app/%E3%82%B3%E3%83%88%E3%83%80%E3%83%9E%E3%83%B3-%E5%85%B1%E9%97%98%E3%81%93%E3%81%A8%E3%81%B0rpg/id1298368256?uo=4


      Mod Requirements:
      - Jailbroken iPhone/iPad/iPod Touch.
      - Filza / iFile or iFunBox / iTools or any other file managers for iOS.
      - Cydia Substrate or Substitute.
      - PreferenceLoader (from Cydia or Sileo).


      Hack Features:
      - 1 Hit Kill
      - Never Die
      - Always Your Turn


      Non-Jailbroken & No Jailbreak required hack(s): https://iosgods.com/forum/79-no-jailbreak-section/
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/


      iOS Hack Download Link:

      Hidden Content
      Download Hack







      Installation Instructions:
      STEP 1: Download the .deb Cydia hack file from the link above.
      STEP 2: Copy the file over to your iDevice using any of the file managers mentioned above or skip this step if you're downloading from your iDevice.
      STEP 3: Using Filza or iFile, browse to where you saved the downloaded .deb file and tap on it.
      STEP 4: Once you tap on the file, you will then need to press on 'Install' or 'Installer' from the options on your screen.
      STEP 5: Let Filza / iFile finish the cheat installation. Make sure it successfully installs, otherwise see the note below.
      STEP 6: If the hack is a Mod Menu, which is usually the case nowadays, the cheat features can be toggled in-game. Some cheats have options that can be enabled from your iDevice settings.
      STEP 7: Turn on the features you want and play the game. You may need to follow further instructions inside the hack's popup in-game.

       

      NOTE: If you have any questions or problems, read our Troubleshooting topic & Frequently Asked Questions topic. If you still haven't found a solution, post your issue down below and we'll do our best to help! If the hack does work for you, post your feedback below and help out other fellow members that are encountering issues.


      Credits:
      - Zahir


      Cheat Video/Screenshots:

      N/A
      • 223 replies
    • (SAOIF Japan) ソードアート・オンライン インテグラル・ファクター v2.7.4 +1 Cheats
      Modded/Hacked App: ソードアート・オンライン インテグラル・ファクター (SAOIF JP) By Bandai Namco Entertainment Inc.
      Bundle ID: jp.co.bandainamcoent.BNEI0323
      iTunes Store Link: https://apps.apple.com/jp/app/%E3%82%BD%E3%83%BC%E3%83%89%E3%82%A2%E3%83%BC%E3%83%88-%E3%82%AA%E3%83%B3%E3%83%A9%E3%82%A4%E3%83%B3-%E3%82%A4%E3%83%B3%E3%83%86%E3%82%B0%E3%83%A9%E3%83%AB-%E3%83%95%E3%82%A1%E3%82%AF%E3%82%BF%E3%83%BC/id1291193987?uo=4


      Mod Requirements:
      - Jailbroken iPhone/iPad/iPod Touch.
      - iGameGod / Filza / iMazing or any other file managers for iOS.
      - Cydia Substrate, Substitute or libhooker depending on your jailbreak.
      - PreferenceLoader (from Cydia, Sileo or Zebra).


      Hack Features:
      - Attack Multiplier
      - No Skill Cooldown
      - No Skill Cost 


      Non-Jailbroken & No Jailbreak required hack(s): https://iosgods.com/forum/79-no-jailbreak-section/
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/


      iOS Hack Download Link:

      Hidden Content
      Download Hack







      Installation Instructions:
      STEP 1: Download the .deb Cydia hack file from the link above. Use Safari/Google Chrome or other iOS browsers to download.
      STEP 2: Once the file has downloaded, tap on it and then you will be prompted on whether you want to open the deb with iGameGod or copy it to Filza.
      STEP 3: If necessary, tap on the downloaded file, and then, you will need to press 'Install' from the options on your screen.
      STEP 4: Let iGameGod/Filza finish the cheat installation. Make sure it successfully installs, otherwise see the note below.
      STEP 5: If the hack is a Mod Menu — which is usually the case nowadays — the cheat features can be toggled in-game. Some cheats have options that can be enabled from your iDevice settings.
      STEP 6: Turn on the features you want and play the game. You may need to follow further instructions inside the hack's popup in-game.

       

      NOTE: If you have any questions or problems, read our Troubleshooting topic & Frequently Asked Questions & Answers topic. If you still haven't found a solution, post your issue down below and we'll do our best to help! If the hack does work for you, please post your feedback below and help out other fellow members that are encountering issues.


      Credits:
      - Zahir


      Cheat Video/Screenshots:

      N/A
      • 47 replies
    • SwordArtOnline: IntegralFactor v2.6.5 +1 Cheats
      Modded/Hacked App: SwordArtOnline: IntegralFactor By Bandai Namco Entertainment Inc.
      Bundle ID: jp.co.bandainamcoent.BNEI0335
      iTunes Store Link: https://apps.apple.com/us/app/swordartonline-integralfactor/id1347075404?uo=4


      Mod Requirements:
      - Jailbroken iPhone/iPad/iPod Touch.
      - iGameGod / Filza / iMazing / or any other file managers for iOS.
      - Cydia Substrate, Substitute or libhooker depending on your jailbreak.
      - PreferenceLoader (from Cydia, Sileo or Zebra).


      Hack Features:
      - Attack Multiplier
      - No Skill Cooldown
      - No Skill Cost 


      Non-Jailbroken & No Jailbreak required hack(s): https://iosgods.com/forum/79-no-jailbreak-section/
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/


      iOS Hack Download Link:

      Hidden Content
      Download Hack







      Installation Instructions:
      STEP 1: Download the .deb Cydia hack file from the link above. Use Safari/Google Chrome or other iOS browsers to download.
      STEP 2: Once the file has downloaded, tap on it and then you will be prompted on whether you want to open the deb with iGameGod or copy it to Filza.
      STEP 3: If necessary, tap on the downloaded file, and then, you will need to press 'Install' from the options on your screen.
      STEP 4: Let iGameGod/Filza finish the cheat installation. Make sure it successfully installs, otherwise see the note below.
      STEP 5: If the hack is a Mod Menu — which is usually the case nowadays — the cheat features can be toggled in-game. Some cheats have options that can be enabled from your iDevice settings.
      STEP 6: Turn on the features you want and play the game. You may need to follow further instructions inside the hack's popup in-game.

       

      NOTE: If you have any questions or problems, read our Troubleshooting topic & Frequently Asked Questions & Answers topic. If you still haven't found a solution, post your issue down below and we'll do our best to help! If the hack does work for you, please post your feedback below and help out other fellow members that are encountering issues.


      Credits:
      - Zahir


      Cheat Video/Screenshots:

      N/A
      • 238 replies
    • Tailed Demon Slayer v1.6.13 +16 Jailed Cheats
      Modded/Hacked App: Tailed Demon Slayer By cookapps
      Bundle ID: com.cookapps.taileddemonslayer
      iTunes Store Link: https://apps.apple.com/us/app/tailed-demon-slayer/id1587114188?uo=4


      Mod Requirements:
      - Non-Jailbroken/Jailed or Jailbroken iPhone/iPad/iPod Touch.
      - Sideloadly / Cydia Impactor or alternatives.
      - A Computer Running Windows/macOS/Linux with iTunes installed.


      Hack Features:
      - Damage Multiplier
      - Defence Multiplier
      - No Skills Cooldown
      - Attack Speed Multiplier
      - Move Speed Multiplier
      - Add VIP*
      - Add Pet*
      - Add Card Point*
      - Add Box*
      - Add All Items*
      - All Items Max Level*
      - Max Level*
      - Unlimited Currencies*
      - Max Skill Level*
      - Relics Max Level*
      - Skip 100 Stages*

      * Go to Settings → Click Save Data


      Jailbreak required hack(s): 


      iOS Hack Download Link:

      Hidden Content
      React or reply to this topic to see the <a href='https://iosgods.com/topic/3762-info-how-to-unlockview-the-hidden-content-on-iosgods/?do=findComment&comment=78119'>hidden content & download link</a>.







      • 222 replies
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines