swstack

swstack (102)

swstack

JavaScript - 17

JavaScript - 17: String Methods You are given a string. Use string methods to: Print all the results using console.log(). let text = "I love learning JavaScript!"; console.log("Uppercase:", text.toUpperCase()); console.log("Length:", text.length); console.log("Contains 'JavaScript':", text.includes("JavaScript")); console.log("Replaced:", text.replace("JavaScript", "coding"));

Continue reading...
swstack

JavaScript - 16

JavaScript - 16: Working with Objects & Methods Create an object called calculator that has three methods: add, subtract, and multiply. Then use the calculator to perform some operations and print the results. let calculator = { add: function(a, b) { return a + b;…

Continue reading...
swstack

JavaScript - 15

JavaScript - 15: Advanced Array Methods (.map() and .filter()) You have an array of numbers. Use .map() to create a new array with each number doubled, and .filter() to create an array with only numbers greater than 10. Print both results. let numbers = [5,…

Continue reading...
swstack

JavaScript - 14

JavaScript - 14: Event Listeners (Click Events) Add a click event to the button so that when clicked, it changes the text and color of the message below. const button = document.getElementById("action-btn"); const message = document.getElementById("message"); button.addEventListener("click", function() { message.textContent = "Button was clicked! 🎉";…

Continue reading...
swstack

JavaScript - 13

JavaScript - 13: Functions with Return Values Create two functions: one that adds two numbers and returns the sum, and another that multiplies two numbers and returns the product. Test them with console.log(). function add(a, b) { return a + b; } function multiply(a, b)…

Continue reading...