Skip to content

Instantly share code, notes, and snippets.

@jayjoshi1611
jayjoshi1611 / 10_fizzBuzz.js
Created January 30, 2026 12:38
JavaScript implementation of the classic FizzBuzz problem
function fizzBuzz(n) {
const result = [];
for (let i = 1; i <= n; i++) {
if (i % 3 === 0 && i % 5 === 0) {
result.push("FizzBuzz");
} else if (i % 3 === 0) {
result.push("Fizz");
} else if (i % 5 === 0) {
result.push("Buzz");
@jayjoshi1611
jayjoshi1611 / 09_calculateTotal.js
Created January 30, 2026 12:29
JavaScript function to calculate total cart value using price and quantity
function calculateTotal(cart) {
let total = 0;
for (let i = 0; i < cart.length; i++) {
const price = Number(cart[i].price);
const quantity = Number(cart[i].quantity);
total += price * quantity;
}
return total;
}
@jayjoshi1611
jayjoshi1611 / 07_titleCase.js
Created January 30, 2026 12:04
JavaScript Title Case Function to capitalize first letter of each word
function titleCase(sentence) {
const words = sentence.split(' ');
for (let i = 0; i < words.length; i++) {
if (words[i]) {
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1).toLowerCase();
}
}
return words.join(' ');
}
@jayjoshi1611
jayjoshi1611 / 04_isPalindrome.js
Last active January 31, 2026 07:10
Check whether a string is palindrome using JavaScript functions
function isPalindrome(str) {
const cleanedStr = str.toLowerCase().replace(/[^a-z0-9]/g, "");
const reversedStr = cleanedStr.split("").reverse().join("");
return cleanedStr === reversedStr;
}
module.exports = { isPalindrome };
@jayjoshi1611
jayjoshi1611 / 01_calculateBMI.js
Created January 30, 2026 08:57
JavaScript BMI Calculator using functions and conditional logic
function calculateBMI(weight, height) {
const bmi = weight / (height * height);
if (bmi < 18.5) {
return "Underweight";
} else if (bmi >= 18.5 && bmi < 24.9) {
return "Normal weight";
} else if (bmi >= 25 && bmi < 29.9) {
return "Overweight";
} else {