
polaryeti
Members-
Posts
54 -
Joined
-
Last visited
Everything posted by polaryeti
-
https://codepen.io/pelko/pen/jOpBmPN Here's the full code. snakeArr.unshift({ x: snakeArr[0].x + inputDir.x, y: snakeArr[0].y + inputDir.y }) This is the code to increase the size of snake once it collides with food. The code above it is working. foodSound.play(); Similarly, the code below it is working //change food location let a = 2; b = 16; food = { x: Math.round(a + (b - a) * Math.random()), y: Math.round(a + (b - a) * Math.random()) } What went wrong? Please help me fix the issue. There are no errors in console.
-
input Direction confusion in snake game javascript
polaryeti replied to polaryeti's topic in Javascript Help
My confusion is cleared. arrSnake=[{x:0,y:1}] inputDir={x:0,y:1} are 2 different object names. It doesn't matter if we use same key name for both of them. -
input Direction confusion in snake game javascript
polaryeti replied to polaryeti's topic in Javascript Help
let snakeArr = [ { x: 13, y: 15 } ] But in this code, we mean x and y are grid co-ordinates. How can we now tell in this question case that x and y represents a vector? I am not getting it. Please help. -
Here's the full code: https://codepen.io/pelko/pen/jOpBmPN This is the code that I'm interested in: window.addEventListener("keydown", e => { inputDir = { x: 0, y: 1 }; moveSound.play(); switch (e.key) { case "ArrowUp": inputDir.x = 0; inputDir.y = -1; break; case "ArrowDown": inputDir.x = 0; inputDir.y = 1; break; case "ArrowLeft": inputDir.x = -1; inputDir.y = 0; break; case "ArrowRight": inputDir.x = 1; inputDir.y = 0; break; } }) What is inputDir variable? (I didn't write this code, I'm learning it from a tutorial, you know tutorials don't cover stuffs well). What I'm not understanding is why are we setting inputDir at 0th row, 1st column? What does that mean? Can you provide some explanations with figures(if possible) about this issue?
-
How does props program flow work in react js?
polaryeti replied to polaryeti's topic in Javascript Help
1) Start with App.js 2) It returns Users component. 3) Inside Users component we pass properties name and job. 4) Inside Users.js we access it using props.name and props.job. A figure that helped me. -
App.js: import React from 'react' import Helloworld from './components/HelloWorld'; import Users from "./components/Users"; const App = () => { return ( <div> <h1>List of Users</h1> <Users name="Zino Emi" job="Developer" /> <Users name="Lionel Messi" job="Web Developer" /> <Users name="Cristiano Ronaldo" job="Software Engineer" /> </div> ); }; export default App; src/components/Users.js: import React from 'react' const Users = (props) => { return ( <div> <div className="user"> <h2>Name: {props.name}</h2> <h3>Job:{props.job}</h3> </div> </div> ) } export default Users I'm not understanding the program flow here. What happens first then what? React is really confusing man. Can anyone help me build a mental model of it? Output:
-
I've built this now. Fixed! I'll update the codepen soon.
-
I want to build this. But I'm confused now. I've built this instead: I've built so far. <!-- about me --> <div class="container"> <div class="row"> <div class="col-md-3"><img src="https://i.redd.it/1oxcj4cs3t7a1.jpg" class="about-me-image" alt=""> </div> <div class="col-md-9 d-flex flex-column align-items-end"> <p class="text-danger">MY INTRO</p> <h1>About Me</h1> <p>Lorem ipsum viverra feugiat. Pellen tesque libero ut justo, ultrices in ligula. Semper at tempufddfel. Lorem ipsum dolor sit amet consectetur adipisicing elit. Non quae, fugiat consequatur voluptatem nihil ad. Lorem ipsum dolor sit amet.</p> <p>Name : Mary Ateer</p> <p>Age : 26 years</p> <p>From : London,UK</p> <p>Email : [email protected]</p> </div> </div> </div> Here's the full codepen. https://codepen.io/pelko/pen/WNKvdZz How do I build that?
-
I did it badly. by giving margin-right:25%.
-
https://demo.w3layouts.com/demos_new/template_demo/28-07-2021/biodata-liberty-demo_Free/2002651968/web/index.html This is the website that I am trying to build. This is my current navbar. This is what I want to build. My focus is on "Home" to "Contact". I want to put it at the center of the page like in the second one. My guess was to do display:flex justify-content: center. But it didn't work. Please guide me how to make it work? Here's the codepen. https://codepen.io/pelko/pen/WNKvdZz
-
Promises syntax that I learnt: let p = new Promise(function (resolve, reject) { let x = 20, y = 20; if (x == y) { resolve(); } else { reject(); } }) p.then(function () { console.log("that's correct"); }) .catch(function () { console.log("that's not correct"); }) I don't even understand what happens here, the flow control of here. My mild guess is when resolve is called .then part happens, and when reject is called .catch part happens. I've like read countless articles, banged my head against the wall but it's still not getting inside my head. I feel so dumb for asynchronous javascript. Please help me understand the program flow step by step in more detail.
-
yes I mean to check palindrome string.
-
I got the idea for problems like factorials or finding sum from 1 to n, where there's a pattern visible. Like this: Source:https://99x.io/blog/recursion-is-not-hard-here-is-the-right-way-to-think I got it for things like addition, subtraction, division, multiplication of two numbers as well. eg: a+b =a+b-1+1 =SUM(a+1,b-1) Now, I am wondering how it'll be for finding a palindrome of a number? I've a solution but I'm not understanding how we came towards it. I'm looking for how to come towards a solution than a solution itself.
-
Update: These are the helpful things that I found from my research. 1) Wes bos 30 days of javascript. 2) https://www.freecodecamp.org/news/javascript-projects-for-beginners/ 3) Go to codewars easier challenges Exercises: Write a function that takes an array of numbers and returns the largest number in the array. Write a function that takes an array of strings and returns a new array containing only the strings that are shorter than 4 characters. Write a function that takes an array of numbers and returns a new array containing only the even numbers from the original array. Write a function that takes an array of numbers and returns the sum of all the numbers in the array. Write a function that takes an array of words and returns a new array containing only the words that are palindromes (words that are spelled the same forwards and backwards, like "racecar" or "level"). Try writing some code using loops, if statements etc to - create a new array that is the reverse of the old array - reverse an array by modifying it in place - see what happens if you use the `delete` keyword on an array element - see what happens if you index or `.find` an element that doesn't exist - try out the built-in functions `map`, `filter`, `reduce`. See if you can get an intuition for what they do and how they're generally useful My university programming course assignments. Based on research, I think I should keep learning more of javascript for the time being.
-
for (i = 1; i <= 5; i++) { for (space = 1; space <= 5 - i; space++) { document.write("0"); } for (j = 1; j <= i; j++) { document.write("X0"); } document.write("<br>"); } I got help from tutorial video to solve this.
-
I want this pattern, what's the logic behind this one? There are lots of blogs online that show code but not teach technique. Share any blogs that you know that teach the logic behind it as well. At i=1, j=5 should be printed as star, rest as white spaces At i=2, j=4,6… At i=3, j=3,5,7…. At i=4,j=2,4,6,8… At i=5, j=1,3,5,7,9… How do I convert this into logic?
-
I'm struggling with frontend. Although my basics of html,css are clear, I'm having trouble in building websites and I'm just putting baby steps towards it(made my first simple html css site today). Thus a guidance from a mentor would be really helpful to me in learning. If I don't find any resources, my plan is to just google and read till I understand. I want to ask this question because I wasted lots of time in the past in bad resources. I bought "CSS Cookbook", turns out it was heavily outdated. I bought Jonas's CSS course in udemy, turns out it wasn't right fit for me because it was unnecessarily project heavy. But imo you make projects on your own rather than by watching and copying others make projects. So, recommend me a course that teaches bootstrap basics and maybe guide me towards building a website using html,css and bootstrap. I'm asking this question so that I don't waste more time on bad resources. Should I focus on bootstrap 5 courses or courses teaching any bootstrap are alright to learn basics?
-
Pardon me if this is not allowed here, you can remove this if this is not allowed. I’ve finished learning basics of HTML and CSS indvidually. I.e topic by topic w/o creating a project. If you want to know the topics that I’ve learnt, I’ve learnt around everything contained in the book “learning web design by jennifer robbins”. Now, I want to do some projects using only html and css. Please share some beginner friendly projects(websites) to do. I’m really stuck and unable to create any projects even though I know the basics. And it’s really scaring me away from programming. I don’t want to look at tutorials that make projects because IDK but that doesn’t help me at this point. They’re building websites with their own thought process and I have a different thought process. IDK what could help me. If you ever faced this phase, do share how you overcame this phase. For eg: https://www.youtube.com/watch?v=ErRRS-rHjWc&list=PLPppPPmk0i3hZCNmbVtcP1hlwDKOdUFX9&index=3 I watch this video. I know everything he’s doing in the video. But when I’ve to create a site without looking at him, I don’t get it. I try to make stuffs but then I fail. I was trying to create this site. But I am stuck here. Words are lost here and I’m failing to debug them. Eg: “CODING.” is overlapped with first navbar. I’m missing a space after “CONTACT” as well. Issues like this happens everytime. How do I get out of them? I’d like to see some projects examples that I can build step by step at this phase with some guidance as well. I tried courses by Jonas Schmedtan but didn’t like it, tried academind’s course and didn’t like it. Both were bestsellers courses. Don’t like brad traversy’s way of presentation either. It says a lot about me and maybe I’m not built for programming. What I could do with CSS could also be done with bootstrap but the main point is that I am fundamentally not able to create something from scratch. I’ve put around 1 month on learning html and css and looking at my current situation, I’m having to rethink about my programming career, if that’s even right for me.
-
Here, custom-label class consists of radio and checkbox labels. The only special feature of inline-block is that you can set width and height like block(and everything appears on same line like inline). label { display: inline-block; width: 25%; font-weight:bold; color: rgb(2,2,149); font-size:20px; } .custom-label{ display:inline; } Say we’ve a situation like this. Full code here: https://codepen.io/pelko/pen/PoaOJNL What’s the need to do display:inline in “custom-label” class? Isn't that redundant.
-
I'm not getting emails on this post, can you fix this issue? I've followed this topic.