Sure! Here's an article featuring 3 JavaScript programs with code examples:
Title: 3 Fun JavaScript Programs to Level Up Your Coding Skills
Introduction:
JavaScript is a versatile programming language that can be used to build interactive web applications. If you're looking to sharpen your coding skills and have some fun along the way, here are 3 JavaScript programs that you can try out. Each program includes code examples to help you understand the implementation. Let's dive in!- Number Guessing Game: The number guessing game is a classic program that challenges the user to guess a random number within a specified range. Here's an example implementation in JavaScript:
let randomNumber = Math.floor(Math.random() * 100) + 1;
let guessedNumber = prompt("Guess a number between 1 and 100:");
if (guessedNumber == randomNumber) {
console.log("Congratulations! You guessed the correct number.");
} else {
console.log("Oops! Better luck next time. The number was: "
+ randomNumber);
}
- TODO List: Create a simple TODO list application that allows users to add and remove tasks. Here's an example implementation:
let todoList = [];
function addTask(task) {
todoList.push(task);
}
function removeTask(task) {
let index = todoList.indexOf(task);
if (index > -1) {
todoList.splice(index, 1);
}
}
addTask("Buy groceries");
addTask("Finish homework");
removeTask("Buy groceries");
console.log(todoList);
// Output: ["Finish homework"]
- Palindrome Checker: A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. Check if a given word is a palindrome using JavaScript:
function isPalindrome(word) {
let reversedWord = word.split("").reverse().join("");
return word === reversedWord;
}
console.log(isPalindrome("racecar")); // Output: true
console.log(isPalindrome("hello")); // Output: false
Thanks for Visting Here ,.
No comments:
Post a Comment