Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //HTML del
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <script src="script.js"></script>
- <link rel="stylesheet" href="style.css">
- <title>Kalkulator</title>
- </head>
- <body>
- <form>
- Value 1: <input type="text" id="value1">
- <br>
- Value 2: <input type="text" id="value2">
- <br><br>
- Operator:
- <select id="operator">
- <option value="a">Add</option>
- <option value="s">Subtract</option>
- <option value="m">Multiply</option>
- <option value="d">Divide</option>
- </select>
- <button type="button" onclick="calc()">Calculate</button>
- </form>
- <div id="result">
- </div>
- </body>
- <script src="script.js"></script>
- </html>
- //JavaScript Del
- function calc()
- {
- //select a specific element based on class or id
- //so parseInt konvertirame od string vo int
- var a=parseInt(document.querySelector("#value1").value);
- var b=parseInt(document.querySelector("#value2").value);
- var op=document.querySelector("#operator").value;
- var calculate;
- if(op==="a")
- {
- calculate=a+b;
- }
- else if(op==="s")
- {
- calculate=a-b;
- }
- else if(op==="m")
- {
- calculate=a*b;
- }
- else if(op==="d")
- {
- calculate=a/b;
- }
- document.querySelector("#result").innerHTML=calculate;
- //inserts a vlue inbetween HTML tags
- }
Advertisement
Add Comment
Please, Sign In to add comment