-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
128 lines (99 loc) · 3.74 KB
/
app.js
File metadata and controls
128 lines (99 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Chapter 6-9 MATH EXPRESSIONS
// question1
// 1. Write a program to take a number in a variable, do the
// required arithmetic to display the following result in your
// browser:
var a=10;
document.write("<br><br>The value of a is: "+a)
++a;
document.write("<br>The value of ++a is: "+a);
document.write("<br>Now the value of a is: "+a);
document.write("<br><br><br>The value of a++ is: "+ a++);
document.write("<br>Now the value of a is: "+a);
document.write("<br><br><br>The value of --a is: "+ --a);
document.write("<br>Now the value of a is: "+a);
document.write("<br><br><br>The value of a-- is: "+ a--);
document.write("<br>Now the value of a is: "+a+"<br><br>");
// question2
// 2. What will be the output in variables a, b & result after
// execution of the following script:
var a = 2, b = 1;
var result = --a - --b + ++b + b--;
// Explain the output at each stage:
--a;
// At --a it is 1 because the value is 1
--a - --b;
// At this stage b is 0 so --a - --b=1;
// --a - --b + ++b = 1 - 0 + 0=2;
// --a - --b + ++b + b--=;
var a = 2, b = 1;
var result = --a - --b + ++b + b--;
document.write("result is "+result+"<br>");
// question3
// 3. Write a program that takes input a name from user &
// greet the user.
var name=prompt("Whats your name?");
alert("Your name is " + name);
// question4
// 5. Write a program to take input a number from user &
// display it’s multiplication table on your browser. If user
// does not enter a new number, multiplication table of 5
// should be displayed by default.
var num=prompt("Enter a number: ");
var num1=5;
var mul;
if(!num)
{
for(var i=1;i<=10;i++)
{
mul=num1*i;
document.write(num1+" x "+i+" = "+mul+"<br>");
}
}
else
{
for(var i=1;i<=10;i++)
{
mul=num*i;
document.write(num+" x "+i+" = "+mul+"<br>");
}
}
// question5
// 6. Take
// a) Take three subjects name from user and store them in 3
// different variables.
var sub1,sub2,sub3;
sub1=prompt("Enter first subject name");
sub2=prompt("Enter second subject name");
sub3=prompt("Enter third subject name");
// b) Total marks for each subject is 100, store it in another
// variable.
var total_marks = 100;
// c) Take obtained marks for first subject from user and
// stored it in different variable.
var x=prompt("Enter obtained marks for subject one ");
var obtained_marks1 = parseInt(x);
// d) Take obtained marks for remaining 2 subjects from user
// and store them in variables.
var y=prompt("Enter obtained marks for subject two ");
var obtained_marks2 = parseInt(y);
var z=prompt("Enter obtained marks for subject three ");
var obtained_marks3 = parseInt(z);
var percent1=(obtained_marks1/total_marks)*100;
var percent2=(obtained_marks2/total_marks)*100;
var percent3=(obtained_marks3/total_marks)*100;
// e) Now calculate total marks and percentage and show the
// result in browser like this.(Hint: user table)
var Total=total_marks*3;
var TotalPercentage;
var obtained=obtained_marks1+obtained_marks2+obtained_marks3;
TotalPercentage=(obtained/Total)*100;
var head1 = "Subject";
var head2 = "Total Marks";
var head3 = "Obtained Marks";
var head4 = "Percentage";
document.write(head1.bold()+" "+head2.bold()+" "+head3.bold()+" "
+head4.bold()+"<br>"+sub1+" "+total_marks+" "+obtained_marks1+" "+percent1+"<br>"
+sub2+" "+total_marks+" "+obtained_marks2+" "+percent2+"<br>"
+sub3+" "+total_marks+" "+obtained_marks3+" "+percent3+"<br>"
+" "+Total+" "+obtained+" "+" "+TotalPercentage+"<br>");