0% found this document useful (0 votes)
25 views

rn4 js1

This document provides code for a simple JavaScript and HTML arithmetic expression evaluator. It includes HTML and CSS code to display a form with input fields for two numbers and buttons to perform arithmetic operations like addition, subtraction, etc. JavaScript functions are defined to handle each button click event, perform the corresponding arithmetic operation on the input numbers, and display the result.

Uploaded by

newsneha775
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

rn4 js1

This document provides code for a simple JavaScript and HTML arithmetic expression evaluator. It includes HTML and CSS code to display a form with input fields for two numbers and buttons to perform arithmetic operations like addition, subtraction, etc. JavaScript functions are defined to handle each button click event, perform the corresponding arithmetic operation on the input numbers, and display the result.

Uploaded by

newsneha775
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical 1 : Write simple JavaScript with HTML for arithmetic expression evaluation and message printing.

Code:

<html>

<head>

<title>Experiment 1</title>

<style>

div {

background-color: #42f5ce;

width: 400px;

border: 10px solid b;

padding: 50px;

margin: 20px;

margin: auto;

</style>

</head>

<body>

<div>

<h2> Arithmetic Operations </h2><br><br>

<form name="Experiment">

<label for="var1">Enter the first number:</label>

<input type="text" name="var1"><br><br>

<label for="var2">Enter the second number:</label>

<input type="text" name="var2"><br><br>

<input type="button" value="ADDITION" onclick="Add()">

<input type="button" value="SUBTRACTION" onclick="Sub()">

<input type="button" value="MULTIPLICATION" onclick="Mul()"><br><br>

<input type="button" value="DIVISION" onclick="Div()">

<input type="button" value="MODULUS" onclick="Mod()">

<input type="button" value="INCREMENT" onclick="Inc()"><br><br>

<input type="button" value="DECREMENT" onclick="Dec()">

<input type="button" value="SQUARE" onclick="sq()">

<input type="button" value="CUBE" onclick="cu()"> <br><br><br>


<label for="result">Result:</label>

<input type="text" name="result"><br><br>

</form>

</div>

<script type="text/javascript">

function Add()

var var1 = parseInt(Experiment.var1.value); var var2 =

parseInt(Experiment.var2.value); var result = var1 + var2; Experiment.result.value =

result;

function Sub()

var var1 = parseInt(Experiment.var1.value); var var2 =

parseInt(Experiment.var2.value); var result = var1 - var2; Experiment.result.value =

result;

function Mul()

var var1 = parseInt(Experiment.var1.value); var var2 =

parseInt(Experiment.var2.value); var result = var1 * var2; Experiment.result.value =

result;

function Div()

var var1 = parseInt(Experiment.var1.value); var var2 =

parseInt(Experiment.var2.value); var result = var1 / var2; Experiment.result.value =

result;

function Mod()

var var1 = parseInt(Experiment.var1.value); var var2 =

parseInt(Experiment.var2.value); var result = var1 % var2; Experiment.result.value =


result;

function Inc()

var var1 = parseInt(Experiment.var1.value); var1++; var result = var1;

Experiment.result.value = result;

function Dec()

var var1 = parseInt(Experiment.var1.value); var1--; var result = var1;

Experiment.result.value = result;

function sq()

var var1 = parseInt(Experiment.var1.value); var result = var1 * var1;

Experiment.result.value = result;

function cu()

var var1 = parseInt(Experiment.var1.value); var result = var1 * var1 * var1;

Experiment.result.value = result;

</script>

</body>

</html>
Output:-

You might also like