Created
June 20, 2025 08:36
-
-
Save godswillJohn/a54987ba0d1fb94e7cc7b4546dcfe013 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NUMBER 1 | |
function factorial(n) { | |
if (n < 0) { | |
return "Factorial is not defined for negative numbers"; | |
} | |
if (n === 0 || n === 1) { | |
return 1; | |
} | |
let result = 1; | |
for (let i = 1; i <= n; i++) { | |
result *= i; | |
} | |
return result; | |
} | |
console.log(factorial(4)); | |
// NUMBER 2 | |
let arrayOfNumbers = [1, 2, 3, 4, 5]; | |
let i; | |
let max = arrayOfNumbers[0]; | |
for (i = 1; i < arrayOfNumbers.length; i++){ | |
if (arrayOfNumbers[i] > max) { | |
max = arrayOfNumbers[i]; | |
} | |
} | |
console.log("The largest number is: " + max); | |
// NUMBER 3 | |
let text = "Hello World!"; | |
let num = 0; | |
for (let i = 0; i < text.length; i++) { | |
let character = text.charAt(i).toLowerCase(); | |
let isLetter = character >= 'a' && character <= 'z'; | |
let isVowel = 'aeiou'.includes(character); | |
if (isLetter && !isVowel) { | |
num++; | |
} | |
} | |
console.log("Number of consonants:", num); | |
// NUMBER 4 | |
let multiplicationTable = 5; | |
for (let i = 1; i <= 10; i++) { | |
console.log(`${multiplicationTable} x ${i} = ${multiplicationTable * i}`); | |
} | |
//NUMBER 5 | |
function rv(string, callBack) { | |
let str = string.toLowerCase(); | |
let reversedString = str.split('').reverse().join(''); | |
callBack(reversedString); | |
} | |
rv("Hello World!", function(reversed) { | |
console.log("Reversed string:", reversed); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment