-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
69 lines (67 loc) · 2.29 KB
/
test.js
File metadata and controls
69 lines (67 loc) · 2.29 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
/*
1- Write a JavaScript program to know if the input is + or - , " 0 considered as + "?
*/
console.log('task 1 solution:');
alert('test possitive or negative number');
var num_test =prompt('please enter your number');
if (num_test>=0){console.log('the input number is possitive '+ num_test);}
else{console.log('the input number is negative '+num_test);}
/*
2- Write a JavaScript program takes 3 input from the user and print the max on the console?
*/
console.log('task 2 solution:');
alert('enter three numbers to find the max');
var num1 = prompt('please enter first numbers');
var num2 = prompt('please enter second numbers');
var num3 = prompt('please enter thired numbers');
console.log ('the numbers are ');
console.log(num1);
console.log(num2);
console.log(num3);
if (num1 > num2 && num1 > num3)
{console.log ('the max number is '+ num1);}
else if(num2 > num1 && num2 > num3)
{console.log('the max number is '+ num2);}
else console.log ('the max number is '+ num3)
/*
3- Write a JavaScript for loop that will iterate from 0 to 20. For each iteration,
it will check if the current number is odd or even, and display a message on the console?*/
console.log('task 3 solution:');
alert('you will enter 20 numbers to check odd or even ');
for (var i=0;i<20;i++)
{
var x=prompt('please enter your number');
if ((x % 2) == 0 || x== 0)
{ console.log (x+' even number');}
else console.log(x+' odd number')
}
/*
4- Write a JavaScript program to calculate the sum of even numbers from 1-100 ?
*/
console.log('task 4 solution:');
alert('we will find the summation of even numbers from 1-100');
var sumeven = 0 ;
for (var i=1; i<= 100; i++)
{
if ((i % 2)==0)
{sumeven=sumeven+ i ; }
}
console.log('the summition of even number from 1-100 is : ' + sumeven);
/*
5- Write a JavaScript program to take 2 numbers from the user and print
ex:-
num1 = 3
num2 = 3
the sum is 6
the multiplication is 9
*/
console.log('task 5 solution:');
alert('enter two numbers to find the summation and multiplication')
var y = parseInt(prompt('please enter first numbers'));
var z = parseInt(prompt('please enter second numbers'));
console.log ('num1 = ' + y) ;
console.log ('num2 = '+ z);
var sum = (y + z);
console.log('the sum is ' + sum) ;
var multi =y*z ;
console.log ('the multiplication is '+ multi) ;