🚀 Starting my 30 Days of JavaScript – Logical Thinking Series. Goal: Improve problem-solving skills by building one small project every day. Day 1: Rock Paper Scissors Game 🎮 Built using conditional logic and random value generation. Here code: let playGame = confirm("Shall we play rock, paper, or scissors?"); if (playGame) { //play let playerChoice = prompt("Please enter rock, paper, or scissors."); if (playerChoice) { let playerOne = playerChoice.trim().toLowerCase(); if ( playerOne === "rock" || playerOne === "paper" || playerOne === "scissors" ) { let computerChoice = Math.floor(Math.random() * 3 + 1); let computer = computerChoice === 1 ? "rock" : computerChoice === 2 ? "paper" : "scissors"; let result = playerOne === computer ? "Tie game!" : playerOne === "rock" && computer === "paper" ? `playerOne: ${playerOne}\nComputer: ${computer}\nComputer wins!` : playerOne === "paper" && computer === "scissors" ? `playerOne: ${playerOne}\nComputer: ${computer}\nComputer wins!` : playerOne === "scissors" && computer === "rock" ? `playerOne: ${playerOne}\nComputer: ${computer}\nComputer wins!` : `playerOne: ${playerOne}\nComputer: ${computer}\nplayerOne wins!`; alert(result); let playAgain = confirm("Play Again?"); playAgain ? location.reload() : alert("Ok, thanks for playing."); } else { alert("You didn't enter rock, paper, or scissors."); } } else { alert("I guess you changed your mind. Maybe next time."); } } else { alert("Ok, maybe next time."); } #JavaScript #WebDevelopment #LearningJourney #30DaysOfCode #Frontend
More Relevant Posts
-
Hi friends 👋 Welcome to Day 2 of my 30 Days JavaScript Logical Thinking Challenge. Today I built a Number Guessing Game 🎯 🔹 How it works: The computer generates a random number between 1 and 10 The user enters a guess The program checks if the guess is correct, too high, or too low 🔹 Concepts Used: i) Math.random() ii) Math.floor() iii) prompt() iv) if / else v) Type conversion using Number() vi) Comparison operators 🔹 What I Learned: Converting string input into numbers Comparing values logically Giving meaningful feedback to users Improving problem-solving skills Here is my cod: let randomNumber = Math.floor(Math.random() * 10) + 1; let userGuess = prompt("Guess a number between 1 and 10:"); if (userGuess !== null) { let guess = Number(userGuess); if (isNaN(guess)) { alert("Please enter a valid number."); } else if (guess === randomNumber) { alert("Correct! You guessed the right number."); } else if (guess > randomNumber) { alert("Too high! Try again."); } else { alert("Too low! Try again."); } } else { alert("Maybe next time!"); } #JavaScript #WebDevelopment #LearningJourney #30DaysOfCode #Frontend
To view or add a comment, sign in
-
This project was a fantastic way to dive deeper into Local Storage, ensuring that even after a page refresh, my saved resources stay right where I put them. 🛠️ Key Features: Persistent Storage: Uses localStorage so your data doesn't vanish. Form Validation: Simple logic to ensure URLs are formatted correctly before saving. Dynamic UI: JavaScript handles the DOM manipulation to inject new bookmarks instantly. Clean Design: A responsive, "dark mode" inspired layout for a modern feel. check my GitHub repo: 🔗 https://lnkd.in/gmeiah58 🚀 day2 #100DaysOfCode #WebDevelopment #JavaScript #Frontend #HTML #CSS #Programming #LearningToCode
To view or add a comment, sign in
-
🤯 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭: 𝐖𝐡𝐞𝐫𝐞 𝐋𝐨𝐠𝐢𝐜 𝐆𝐨𝐞𝐬 𝐭𝐨 𝐃𝐢𝐞 (𝐚𝐧𝐝 𝐖𝐡𝐲) If you’ve ever looked at your console and thought, "That shouldn't be possible," you’re not alone. JavaScript is a language built on "best intentions" that often lead to total logic meltdowns. I’ve put together the attached guide (PDF) breaking down of the most infamous "WTFJS" moments—from why 0.1 + 0.2 isn't 0.3 to how the console can literally yell "banana" at you. 🔍 𝐖𝐡𝐚𝐭’𝐬 𝐚𝐜𝐭𝐮𝐚𝐥𝐥𝐲 𝐡𝐚𝐩𝐩𝐞𝐧𝐢𝐧𝐠 𝐮𝐧𝐝𝐞𝐫 𝐭𝐡𝐞 𝐡𝐨𝐨𝐝? Most of these "bugs" actually follow three very specific (and very weird) rules: • 𝐓𝐲𝐩𝐞 𝐂𝐨𝐞𝐫𝐜𝐢𝐨𝐧 (𝐓𝐡𝐞 𝐒𝐢𝐥𝐞𝐧𝐭 𝐊𝐢𝐥𝐥𝐞𝐫): JavaScript hates throwing errors. If you try to subtract a number from a string, it won't stop you—it will just "guess" what you meant. Sometimes it guesses wrong. • 𝐓𝐡𝐞 𝐈𝐄𝐄𝐄 𝟕𝟓𝟒 𝐒𝐭𝐚𝐧𝐝𝐚𝐫𝐝: JS doesn't store numbers the way humans write them. It uses binary floating-point math. When you deal with large integers or small decimals, you’re seeing the "rounding errors" of the machine. • 𝐓𝐫𝐮𝐭𝐡𝐲 𝐯𝐬. 𝐅𝐚𝐥𝐬𝐲: In JS, an empty array [] is technically "truthy," but when compared to a boolean using ==, the engine performs a series of hidden conversions that defy common sense. 🛡️ 𝐇𝐨𝐰 𝐭𝐨 𝐬𝐭𝐚𝐲 𝐬𝐚𝐧𝐞: • 𝐒𝐭𝐫𝐢𝐜𝐭 𝐄𝐪𝐮𝐚𝐥𝐢𝐭𝐲 (===): Never trust the double equals. • 𝐌𝐚𝐧𝐮𝐚𝐥 𝐂𝐚𝐬𝐭𝐢𝐧𝐠: Don't let JS guess your types; convert them yourself using Number() or String(). • 𝐔𝐬𝐞 𝐁𝐢𝐠𝐈𝐧𝐭: For those massive numbers that keep rounding up. Check out the PDF below for the full breakdown of these logic-defying snippets! Which of these tripped you up the most when you were starting out? Let’s swap horror stories in the comments. 👇 #Javascript #WebDevelopment #Programming #SoftwareEngineering #CodingLife #TechHumor
To view or add a comment, sign in
-
Building on the basics of JavaScript, I’ve gained a solid understanding of how core components build a functional system. Writing code is the heart of this process, and seeing these concepts integrate is a major highlight of my learning. I have been practicing variable assignments using let, const, and var, while using typeof to identify different data types. I also learnt how to structure Control Flow through if/else statements, switch cases, and comparison operators. By using logical operators—specifically AND (&&) and OR (||)—along with strict equality (===), I can now set multiple rules for my code. I understand how to ensure that if a primary condition isn't met, the "else" logic applies correctly so the program follows a specific path. I also learnt how to use for loops combined with the .length property. This allows the code to automatically track the number of characters or items in a dataset. Instead of hard-coding values, I can now write dynamic code that adjusts to the data it receives. I am still working through the fundamentals, and I am excited to see how everything will work together once the foundation is complete! #JavaScript #WebDevelopment #CodingJourney #SoftwareEngineering #Techcrush #Frontend
To view or add a comment, sign in
-
-
I used to think I understood this in JavaScript… Until it completely broke my code. 😅 At first, it seemed simple. 👉 this = the current object… right? But then I ran into weird behavior: • Inside a function → this was window • Inside strict mode → this became undefined • Inside an object method → it worked perfectly • Inside callbacks → chaos again That’s when I realized: 👉 this is NOT about where the function is written. 👉 It’s about how the function is called. That one shift changed everything. Here’s the simple way to think about it: • Global → this = global object • Object method → this = the object • Function → depends on strict mode • Constructor → this = new instance • call/apply/bind → you control this Once you understand this, JavaScript starts making a lot more sense. If you're struggling with this, I wrote a simple guide breaking it down step-by-step 👇 And full blog here: https://lnkd.in/dvV8_aZq 💡 My takeaway: Don’t memorize this. Understand the execution context. What confused you the most about this when you were learning JavaScript? Hitesh Choudhary | Piyush Garg | Akash Kadlag | Suraj Kumar Jha | Shubham Waje #chaicode#javascript #webdevelopment #coding #frontend #programming #developers #learninpublic #softwareengineering
To view or add a comment, sign in
-
-
Hot take: var isn't just outdated — it was always broken. We just didn't have anything better. I wrote a deep-dive blog post explaining exactly why modern JavaScript dropped it: 1. No block scope — variables leak outside { } blocks 2. Attaches to the global window object 3. Silent hoisting — returns undefined before declaration with zero warnings 4. Can't shadow let/const across scope boundaries 5. Forces you to write closure workarounds that let fixes in one character The post also covers the Temporal Dead Zone, the classic setTimeout loop bug, and a real code example from a closure deep-dive. If you've ever been told "just don't use var" but never understood why — this one's for you. #JavaScript #ES6 #WebDevelopment #Frontend #Programming #TechBlog
To view or add a comment, sign in
-
🚀 Day 5 of My JavaScript Journey Today was all about understanding how JavaScript handles numbers, memory, and randomness — and honestly, it cleared a lot of confusion 🔥 Here’s what I learned 👇 📌 Stack vs Heap Memory Stack → stores primitive values (fast & simple) Heap → stores objects (reference based)👉 This explains why objects behave differently when copied 📌 Number Data Type & Methods toFixed() → controls decimal places toPrecision() → controls total digits toString() → converts number to string⚠️ Important: toFixed() returns a string, not a number! 📌 Primitive vs Object Comparison Primitives compare by value Objects compare by reference👉 That’s why new Number() is a bad practice ❌ 📌 Truthy & Falsy Twist new Number(0) is truthy 😲👉 Because it’s an object, not a primitive 📌 Math Object Magic 🧠 Math.ceil() → round up Math.floor() → round down Math.random() → gives value between 0 and 1 📌 Random Number Tricks 🎲 0–9 → Math.floor(Math.random() * 10) 1–10 → Math.floor(Math.random() * 10) + 1 Dice roll (1–6) → Perfect real-life example 📌 OTP Generation 🔐 Easy to generate using Math.random() But ❗ NOT secure for real apps👉 Secure apps use crypto libraries 💡 Big Takeaway:Understanding how JavaScript works internally (memory + types) is way more important than just writing code #JavaScript #WebDevelopment #CodingJourney #MERNStack
To view or add a comment, sign in
-
-
𝗩𝗮𝗻𝗶𝗹𝗹𝗮 𝗖𝗼𝗱𝗲: 𝗛𝗼𝘄 𝗩𝟴 𝗖𝗼𝗺𝗽𝗶𝗹𝗲𝘀 𝗬𝗼𝘂𝗿 𝗖𝗼𝗱𝗲 You spend your days working with JavaScript. But have you ever wondered what happens behind the scenes? When you run your code, V8 - the JavaScript engine - takes over. It's not just a compiler, it's a performance expert. Here's how it works: - V8 reads your code as a stream of characters - It builds a blueprint, called the Abstract Syntax Tree (AST) - V8 is lazy, so it only builds the full AST when needed - It uses an interpreter, called Ignition, to turn the AST into bytecode - Bytecode is like stage directions for your code When your code runs, V8 watches and takes notes. It looks for hot paths - loops that run many times. When it finds them, it uses Sparkplug to compile the bytecode to machine code. If a function is super hot, V8 uses Maglev to create a baseline optimized version. For critical code, V8 uses TurboFan, an optimizing compiler. TurboFan makes a bet: it assumes your code will keep doing what it's doing. If you keep passing it the same types, your code runs fast. But if you change the type, V8 falls back to the slower bytecode. To keep V8 happy, write consistent code. Use consistent types, small functions, and avoid deleting properties. JavaScript is not slow - your misuse of it is. V8 is a masterpiece of engineering. It's a Just-In-Time compiler that does adaptive optimization. When you write code, you're feeding an algorithm. Understand how it thinks, and you'll stop fighting the machine. Source: https://lnkd.in/g4Fkem6a
To view or add a comment, sign in
-
How I Built a Dynamic Recipe Form with Vanilla JS! 🛠️💻 In this part of my Mom’s Recipe project series, I’m breaking down the form submission logic. Handling complex, multi-step data entry in pure JavaScript was a great challenge! What’s happening in this part: 🧩 Dynamic UI: Using JS to add/remove ingredient and instruction fields on the fly. 🖼️ Image Processing: Leveraging the FileReader API to convert uploads into Base64 strings for local storage. 📂 Data Structure: Using the .map() function to organize inputs into a clean JSON object. Building this helped me truly master DOM manipulation and browser storage. Check out the logic in action! 🚀 #Javascript #WebDev #CodingLogic #Frontend #VanillaJS #MomsRecipe #Programming
To view or add a comment, sign in
-
Just published a new blog on Control Flow in JavaScript — titled “𝗗𝗘𝗖𝗜𝗦𝗜𝗢𝗡𝗦.” When I started this JS series, I told myself I’d keep it 𝘀𝗶𝗺𝗽𝗹𝗲 𝗮𝗻𝗱 𝗰𝗹𝗲𝗮𝗿. One concept at a time. So far the series looks like this: 𝟬𝟭 – 𝗝𝗦 𝗩𝗮𝗿𝗶𝗮𝗯𝗹𝗲𝘀 𝟬𝟮 – 𝗢𝗽𝗲𝗿𝗮𝘁𝗼𝗿𝘀 𝗣𝗿𝗼𝗺𝗶𝘀𝗲𝘀 (𝘄𝗶𝗹𝗱 𝗰𝗮𝗿𝗱) 𝟬𝟯 – 𝗗𝗲𝗰𝗶𝘀𝗶𝗼𝗻𝘀 (𝗖𝗼𝗻𝘁𝗿𝗼𝗹 𝗙𝗹𝗼𝘄) It’s interesting how programming really comes down to this.. 𝘴𝘵𝘰𝘳𝘦 𝘥𝘢𝘵𝘢 → 𝘰𝘱𝘦𝘳𝘢𝘵𝘦 𝘰𝘯 𝘪𝘵 → 𝘥𝘦𝘤𝘪𝘥𝘦 𝘸𝘩𝘢𝘵 𝘩𝘢𝘱𝘱𝘦𝘯𝘴 𝘯𝘦𝘹𝘵. That’s what this post focuses on. Also… yes, I’ve been using scorpions in the thumbnails lately. No deep philosophy behind it. I just like how they look. If you're learning JavaScript or revising fundamentals, you might find it useful. 🔗 https://lnkd.in/gR6HsW5E Feedback is always welcome. #JavaScript #WebDevelopment #LearningInPublic
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