-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (52 loc) · 1.5 KB
/
Copy pathscript.js
File metadata and controls
63 lines (52 loc) · 1.5 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
// // Count the vowels in a string
// // vowels are = a,e,i,o,u
// const vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
// // Now call a function which will be Count the Vowels in the string -
// function countVowels(sentence) {
// let count = 0;
// const letters = Array.from(sentence)
// letters.forEach(Function(value){
// if(vowels.includes(value))
// count++
// });
// return count++;
// };
// console.log(countVowels("ikram akbar"));
// program to count the number of vowels in a string
function countVowel(str) {
// find the count of vowels
const count = str.match(/[aeiou]/gi).length;
// return number of vowels
return count;
}
// take input
// const string = prompt('Enter a string: ');
// const result = countVowel(string);
console.log(countVowel("ikram akbar"));
//Write a function that will find out a random number form 1 to 10;
const randomNum = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
console.log(randomNum(2,20))
//
function randomNumber(min, max) {
if (min > max) {
let temp = max;
max = min;
min = temp;
}
if (min <= 0) {
return Math.floor(Math.random() * (max + Math.abs(min) + 1)) + min;
} else {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
}
console.log(randomNumber(10,14));
function randomBetween(min, max) {
if (min < 0) {
return min + Math.random() * (Math.abs(min) + max);
} else {
return min + Math.random() * max;
}
}
console.log(randomBetween(4,2));