@@ -19,6 +19,140 @@ Convert temperature from Celsius to Fahrenheit and vice versa using appropriate
19
19
20
20
Mixed Topics:
21
21
Write a program to find the factorial of a number using a loop.
22
- Create a simple calculator program that performs addition, subtraction, multiplication, and division based on user input*/
22
+ Create a simple calculator program that performs addition, subtraction, multiplication, and division based on user input
23
+
24
+ Some extra advanced questions
25
+ 1.Implement a JavaScript program to print Fibonacci series using a for loop.
26
+ */
23
27
24
28
//Q1
29
+ let num = 10 ;
30
+ let str = "javascript" ;
31
+ let bool = true ;
32
+ let arr = [ "letters" , "numbers" , "datatypes" ] ;
33
+ let obj = {
34
+ name :"indresh" ,
35
+ status :"student" ,
36
+ age :19 ,
37
+ }
38
+ console . log ( num , str , bool , arr , obj ) ;
39
+
40
+
41
+ //Q2
42
+ let number = 10 ;
43
+ if ( number % 2 == 0 ) {
44
+ console . log ( "It is even" )
45
+ }
46
+ else {
47
+ console . log ( "it is odd" )
48
+ }
49
+
50
+ //Q3
51
+ let score = 100 ;
52
+ switch ( true ) {
53
+ case score <= 50 :
54
+ console . log ( "F" ) ;
55
+ break ;
56
+ case score <= 60 :
57
+ console . log ( "E" ) ;
58
+ break ;
59
+ case score <= 70 :
60
+ console . log ( "D" ) ;
61
+ break ;
62
+ case score <= 80 :
63
+ console . log ( "C" ) ;
64
+ break ;
65
+ case score <= 90 :
66
+ console . log ( "B" ) ;
67
+ break ;
68
+ case score <= 100 :
69
+ console . log ( "A" ) ;
70
+ break ;
71
+ default :
72
+ console . log ( "not a valid mark" ) ;
73
+ }
74
+
75
+ //Q4
76
+ for ( let i = 1 ; i <= 10 ; i ++ ) {
77
+ console . log ( i ) ;
78
+ }
79
+
80
+ //Q5
81
+ let table = 5 ;
82
+ for ( let i = 0 ; i <= 10 ; i ++ ) {
83
+ ans = table * i ;
84
+ console . log ( `${ table } * ${ i } = ${ ans } ` ) ;
85
+ }
86
+
87
+ //Q6 - let l = 10 and w = 15 , exp output = 150
88
+ function areaofRect ( length , width ) {
89
+ let area = length * width ;
90
+ console . log ( area ) ;
91
+ }
92
+ areaofRect ( 10 , 15 ) ;
93
+
94
+ //Q7 - cel to farenheit and farenheit to cel - logic
95
+ //farenheit = 9/5 * cel + 32
96
+ function FtoC ( farenheit ) {
97
+ let Celsius = 5 / 9 * ( farenheit - 32 ) ;
98
+ console . log ( `${ farenheit } degree farenheit is equal to ${ Celsius } degree celcius` )
99
+ }
100
+
101
+ function CtoF ( celcius ) {
102
+ let farenheit = ( ( 9 / 5 ) * celcius ) + 32 ;
103
+ console . log ( `${ celcius } degree celcius is equal to ${ farenheit } degree farenheit` )
104
+ }
105
+ FtoC ( 212 ) ;
106
+ CtoF ( 100 ) ;
107
+
108
+ //Q8 - factorial of a number using loops
109
+ let factorialreq = 10 ;
110
+ let factorialTerm = 1 ;
111
+ for ( let i = 1 ; i <= factorialreq ; i ++ ) {
112
+ factorialTerm *= i ;
113
+ }
114
+ console . log ( factorialTerm ) ;
115
+
116
+ //Q9 - simple calculator to perform + - * / based on user input
117
+ let inputnum1 = 10 ;
118
+ let inputnum2 = 20 ;
119
+ let inputoperation = "division" ;
120
+ function add ( a , b ) {
121
+ console . log ( a + b ) ;
122
+ }
123
+ function sub ( a , b ) {
124
+ console . log ( a - b ) ;
125
+ }
126
+ function mul ( a , b ) {
127
+ console . log ( a * b ) ;
128
+ }
129
+ function div ( a , b ) {
130
+ console . log ( a / b ) ;
131
+ }
132
+
133
+ if ( inputoperation == "addition" ) {
134
+ add ( inputnum1 , inputnum2 ) ;
135
+ }
136
+ if ( inputoperation == "substraction" ) {
137
+ sub ( inputnum1 , inputnum2 ) ;
138
+ }
139
+ if ( inputoperation == "multiplication" ) {
140
+ mul ( inputnum1 , inputnum2 ) ;
141
+ }
142
+ if ( inputoperation == "division" ) {
143
+ div ( inputnum1 , inputnum2 ) ;
144
+ }
145
+
146
+ //Q10 - fibonacci series using for loops
147
+ //fibonacci series have a series of numbers and each number in the series is equivalent to the sum of the previous 2 numbers
148
+ let fibonacciTermsreq = 10 ;
149
+ let t1 = 0 ;
150
+ let t2 = 1 ;
151
+ console . log ( t1 ) ;
152
+ console . log ( t2 ) ;
153
+ for ( let i = 1 ; i <= fibonacciTermsreq ; ++ i ) {
154
+ t1 = t2 ;
155
+ t2 = i ;
156
+ let nextterm = t1 + t2 ;
157
+ console . log ( nextterm ) ;
158
+ }
0 commit comments