-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExercise.js
43 lines (40 loc) · 936 Bytes
/
Exercise.js
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
function factor(){
let num = prompt("Enter a num:");
let factor = 2;
while((num % factor) != 0){
factor++;
}
console.log(factor);
}
function findChar(){
let input = prompt("Write a sentence");
let char = prompt("Enter a char");
let index = 0;
let found = false;
while(index < input.length && !found){
if(char == input.charAt(index)){
found = true;
}
index++;
}
if(!found){
console.log("Char not found.");
}
}
function evenOdd(){
for(int i = 0; i <= 20; i++){
if(i % 2 == 1){
console.log( i + " is odd");
}else if(i % 2 == 0){
console.log(i + " is even");
}
}
}
function reverseString(){
let string = prompt("Enter a string");
let newstring = "";
for(i = string.length - 1; i >= 0; i--){
newstring += string.charAt(i);
}
console.log(newstring);
}