Today’s Tiny JavaScript Project I wrote a simple “Fortune Teller” script in JavaScript — it picks a random fortune each time you run it! let fortune1 = "Your cat will look very cuddly today."; let fortune2 = "The weather will be nice tomorrow."; let fortune3 = "Be cautious of your new neighbors."; let fortune4 = "You will find a new hobby soon."; let fortune5 = "It would be wise to avoid the color red today."; let randomNumber = Math.floor(Math.random() * 5) + 1; let selectedFortune = randomNumber; if (randomNumber === 1) selectedFortune = fortune1; else if (randomNumber === 2) selectedFortune = fortune2; else if (randomNumber === 3) selectedFortune = fortune3; else if (randomNumber === 4) selectedFortune = fortune4; else if (randomNumber === 5) selectedFortune = fortune5; console.log(selectedFortune); 🧠 It’s a small project, but a fun way to practice: Random number generation Conditional logic Console output What fortune did you get when you ran it? 👀 #JavaScript #Coding #WebDevelopment #100DaysOfCode #LearnToCode
"Creating a Fortune Teller with JavaScript"
More Relevant Posts
-
👉✅ “Setting a one-week goal to revise JavaScript again.” 💻Topic-1. JavaScript Constructor Function Hey everyone, 👋 Today, let’s talk about an interesting JavaScript topic — the Constructor Function. This is a special type of function that helps us create multiple similar objects without writing the same code again and again! 🔁 🧠 Key points to understand: The name of a constructor function always starts with a capital letter. We use the new keyword when creating an object. It automatically returns a new object. Through this concept, we can explore the basics of Object-Oriented Programming (OOP) in JavaScript — including concepts like inheritance and encapsulation. 🚀 If you’re learning JavaScript, understanding constructor functions is a must-have skill — it makes your code cleaner, reusable, and more efficient! #JavaScript #WebDevelopment #CodingTips #ConstructorFunction #FrontendDevelopment #LearningEveryday
To view or add a comment, sign in
-
-
💡 Understanding Object Methods in JavaScript Working with objects is fundamental in JS. Here's a quick overview of some powerful methods: Object.keys(obj) → Returns all keys of the object. Object.values(obj) → Returns all values of the object. Object.entries(obj) → Returns key-value pairs as arrays. obj.hasOwnProperty("property") → Checks if the object has a specific property. Object.assign({}, obj, { newProperty: "newValue" }) → Creates a new object by merging existing ones. 👉 View the full example on GitHub: https://lnkd.in/dDN-vDkD #JavaScript #FullStack #100xDevs #WebDevelopment #Coding #JSConcepts #LearnJavaScript
To view or add a comment, sign in
-
❓ Are “undefined” and “not defined” the same in JavaScript? Not really. In JavaScript, every declared variable automatically gets the placeholder undefined during the memory allocation phase — meaning the variable exists, but no value has been assigned yet. However, if you try to access a variable that was never declared, JavaScript throws not defined. ➡️ Undefined = declared but not assigned ➡️ Not Defined = not declared at all JavaScript is also a loosely typed language, so variables can change types freely. 💡 Pro tip: Never manually assign undefined. Let JavaScript handle that. #JavaScript #WebDevelopment #Programming #Frontend #LearningJS
To view or add a comment, sign in
-
How JS Converts [] + {} to [object Object] —🤯 JavaScript can be weirdly magical sometimes. Ever tried this in your console? 👇 [] + {} // Output: "[object Object]" At first glance, it looks confusing — why does an empty array and an empty object become a string? Let’s decode the magic 🪄 1️⃣ + Operator in JS The + operator doesn’t just add numbers — it can also concatenate strings. 2️⃣ Type Conversion Happens! [] (empty array) → when converted to string becomes "" (empty string). {} (empty object) → when converted to string becomes "[object Object]". 3️⃣ Final Expression So JS actually does: "" + "[object Object]" → "[object Object]" ✅ Bonus twist: Try reversing it: {} + [] Now it gives 0 because {} is treated as an empty block,not an object. 🤯 JavaScript — where logic meets magic ✨ 🔹 Follow Prashansa Sinha for more fun JS mysteries and simple explanations 👩💻 #JavaScript #WebDevelopment #Coding #Frontend #JS #LearnToCode #Programming #TechCommunity #Developers #CodeNewbie #WebDev
To view or add a comment, sign in
-
🚀 JavaScript Revision Series — Day 3 Today’s revision was all about Operators in JavaScript — the tools that let us do everything from math to logic in our programs! 💻✨ 🟢 Operators Covered: Arithmetic: + - * / % Assignment: =, +=, -=, *= Logical: &&, ||, ! Ternary Operator: condition ? true : false 😄 Fun JS Moment: Remember, 5 + "1" = "51" But 5 - "1" = 4 JS loves to play tricks with operators 😅 --- 🔗 Daily Practice Repo: https://lnkd.in/ejQk84Zg Step by step, one operator at a time — building solid JS foundations! 🚀 #JavaScript #JavaScriptBasics #LearningJourney #WebDevelopment #FrontendDevelopment #CodingJourney #MERNStack #ConsistencyIsKey #SMIT #DeveloperCommunity #Saylani
To view or add a comment, sign in
-
-
Accidentally Discovered Something Cool in JavaScript! 😎 While working on some JavaScript code, I accidentally came across the ! and !! operators - and it turned out to be a really interesting find 😄 At first, I was confused 🤔 but after a bit of testing, it all made sense! - The ! (NOT) operator converts true -> false, and vice versa. - The !! (Double NOT) operator converts any value into its boolean equivalent value and its great for checking if something is truthy or falsy. This tiny trick makes conditions cleaner and helps when validating inputs or checking existence of values in JavaScript. Tiny discoveries like these remind me how fun it is to explore and learn JavaScript every day! 😊 . . . . . . . #WebDevelopment #JavaScript #Frontend #CodingJourney #LearningByDoing #Developer #Coding #LearningToCode #FrontendDevelopment #DevelopersCommunity #CodingTips #CodeWithMe #CleanCode #CodeBetter #DevLife
To view or add a comment, sign in
-
-
🍏 JS Daily Bite #9 — Understanding Function Prototypes Every function in JavaScript has a special property called prototype — the foundation of how inheritance and object construction work in the language. 🔍 The Function Prototype Property All functions (except arrow functions) have a default prototype property Arrow functions ❌ do not have a prototype The prototype object includes a constructor property that points back to the function Each prototype object’s [[Prototype]] links up to Object.prototype 🧱 Adding Properties to Prototypes You can attach properties or methods to a function’s prototype to make them automatically available to all instances created with that function. This is a memory-efficient way to share behavior across instances! ⚡️ 🧩 Creating Instances with new When you use the new operator: A new object is created Its [[Prototype]] is set to the function’s prototype property Instance-specific properties are initialized Shared methods are inherited through the prototype chain 🧭 How Property Lookup Works When accessing a property: JavaScript checks the object itself If not found, it climbs the prototype chain ([[Prototype]]) The search continues until Object.prototype If still not found, the result is undefined 🧠 Key Takeaways Instance properties override prototype properties Prototype properties are shared across all instances The chain always ends at Object.prototype.[[Prototype]] === null Mastering this mechanism is essential for deep JavaScript understanding 💪 🔜 Next in the Series → Comparing Ways to Create and Mutate the Prototype Chain #JavaScript #WebDevelopment #Programming #TechEducation #LearnToCode #SoftwareDevelopment #JSInsights #CodeLearning #Frontend #JSFundamentals #Prototypes #JSDailyBite
To view or add a comment, sign in
-
Hey, Mates. How are you doing? You know, Even experienced devs trip over JavaScript quirks sometimes — here are a few I’ve seen (and made myself 😅 as well): 1. Using var instead of let or const var is function-scoped and can cause weird bugs due to hoisting. ✅ Use let for variables that change and const for ones that don’t. 2. Forgetting to handle async properly Mixing promises, callbacks, and async/await can lead to race conditions or unhandled rejections. ✅ Always await async functions or chain with .then(), and wrap in try/catch. 3. Comparing values incorrectly == does type coercion (and sometimes weirdly!). ✅ Stick to === for strict comparison. 4. Misunderstanding this Arrow functions don’t have their own this — they inherit from the parent scope. ✅ Know when to use arrow functions vs regular ones. 5. Not handling floating-point math 0.1 + 0.2 !== 0.3 (yes, really). ✅ Use libraries like decimal.js or round your values when precision matters. ⸻ These are small details — but they separate good JavaScript from great JavaScript. 💬 What’s a JS mistake you’ve seen (or made) that taught you something valuable? #JavaScript #WebDevelopment #Programming #CodingTips #Frontend
To view or add a comment, sign in
-
8 JavaScript topics that actually matter Been coding for a while now, these keep coming up: → Closures Functions that remember their context. Used everywhere in React hooks and callbacks. → Promises & Async/Await Writing code that waits without freezing. Essential for API calls. → Array Methods map(), filter(), reduce(). Clean data manipulation. → Event Loop How JavaScript handles async ops. Makes everything click once you get it. → Destructuring Cleaner way to pull values from objects and arrays. Saves a lot of lines. → Spread/Rest Operators Copy arrays, merge objects, handle function params. Super useful. → Prototypes & Inheritance How objects actually work under the hood. Important for interviews. → Module Systems Import/export between files. Keeps code organized. These aren't flashy. But knowing them makes everything easier. What topic gave you the most trouble when learning JS? #JavaScript #Coding #WebDevelopment #100DaysOfCode #LearnToCode #FrontendDevelopment #MERNStack #DeveloperTips
To view or add a comment, sign in
-
Today I explored some of the most powerful array methods in JavaScript — map(), filter(), and reduce() ✨ These functions make working with data so much easier and cleaner. 🔹 map() — transforms each element in an array. 🔹 filter() — filters elements based on a condition. 🔹 reduce() — reduces the array to a single value (like sum, average, etc.). While practicing, I understood how combining them can make code much shorter and more readable. Feeling more confident in writing cleaner JavaScript code now! 💻💡 #JavaScript #WebDevelopment #LearningJourney #Coding #FrontendDevelopment #JSMap #Filter #Reduce #Developer
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development