YTread Logo
YTread Logo

4 JavaScript Projects under 4 Hours | JavaScript Projects For Beginners | JavaScript | Simplilearn

Mar 09, 2024
the cell to add the token dot internal html is equal to a blank, so what problem am I saying? Record console points and provide the value you want, it's fine in this console. record what value we can give to the cell to add the token. We got it, it's taking this value to the current cell. dot internal html console.log and inside my console.log we can set this cell to be already taken, so the values ​​are already taken for this. and now we will return those values, after that we will use the else condition and here we use once again if the current player is okay is x, then we will use this option called cell.
4 javascript projects under 4 hours javascript projects for beginners javascript simplilearn
Look, we have this property option available called sent to add tokens. using the cell to add the token, okay, the point text content is equal to the current player, okay and we say game mode, the one you created goes into this game mode, this value calls the current cell and in this right cell the value will be equal to x okay, otherwise we can say send to add symbolic points text content equal to current player okay and say game board current cell equal to like this okay that here we are adding the values ​​so that it closes after that, we can use the function name to make it the winner. check if the user is winner or not then we say winner ok and after that we say spin more more after that we say change we don't have the name of the function called change board header names ok like this which is like that.
4 javascript projects under 4 hours javascript projects for beginners javascript simplilearn

More Interesting Facts About,

4 javascript projects under 4 hours javascript projects for beginners javascript simplilearn...

We are giving it so that as usual we can leave this function for a while and we will call it a little later, so leave it as a full time name, okay, your function is ready, the next thing we need to do is check if it is tied or not ok then we say function so here we say if condition is spin greater than seven alert again ok we can say yield otherwise we can say our type ok after that we are Saying the winning function is a winner, now what? We'll check it, we'll check the constant winning sequences, the winning sequences and I'm sorry, we have this matrix and the different conditions associated with it, we say 0 1 2 probability, we're checking it and then I just copy it right, it's missing 0 1 2 and here it says 3 4 5 6 7 8 and 0 3 6 again 0 3 6 and once again 1 4 7 4 7 and then we have a call two five eight eight then we are checking the zero value for eight and one more last option We will put it is called two four six six, so these conditions we will add now after this matrix, we can say that variable sequences begin for each one and give it the name winner, compose, compost winner and within these variable compounds, we give cell 1 equal. to vary the position of combos 0, then copy and paste three times cell two, cell three and here we get the name of the writer, what one, two, three values ​​we are giving and after that we are checking the condition, let's say yes and here the conditions that We are checking what exactly would be for the game board, we are saying that the game board sets a current player, sorry, the current player sign time percentage goes down, cell 2 of the game board, I just want to copy this on the same line and paste it several times here.
4 javascript projects under 4 hours javascript projects for beginners javascript simplilearn
We are checking the condition for cell 2, cell 3 and cell 3 and then we start the position then we start the position call by cutting this condition called consensus const sense and then equal to document dot get element by or sorry document or selector of query query selector everything and here let's select the position of the point, okay, then we will use the cell point for each cell and inside is what we are passing, they say make the cell id equal to the first child of the point of the cell. okay point data set point id so this is the value you're basically adding it now and we're using one more condition if we're saying if cell id now we're talking about calling cell id triple equal to cell 1 or saline. cell a or salary equal to three, okay, and in that case we can use the cell points list, add points and give the name called board, just give the class name winner, so here we will give the winner and a part of that we can use the other conditions as well so here you are adding the value and now let's say current player is equal to document point you get the item by id so you can basically define it as the current player you want so we can use the current player or the conditions you want. we want, here we use what the cell winner is now a small change instead of using the right player, we can use the current player text, the new variable that we are creating, the current player text, document dot, in instead of saying get element by id, we can say query selector and in To this query selector we will give the value by saying dot board, the value that we are giving here and the query value selector that you gave, let me try to put it in parentheses like this, okay, now here we just check if the current player x then, so in this case, we can say current player, what is the value that we are using?
4 javascript projects under 4 hours javascript projects for beginners javascript simplilearn
Current text, period, internal html, equal to now we can define the value, anyone who wants to operate, we just use a condition called OK, so we say congratulations, OK. and here you see congratulations along with this dollar sign and here we pass the name of the player test point and here the tip tag closes like this, okay, that's the message we're basically printing it and after that we give it this value and we say this message called winner equals true and after that if you want to apply remove that function which we have not written we will talk about it later and we will just say return true again so that your function is ready now and later we can check the condition. if it's filler, if it's winner, or you can say check if time and return false, that's it.
Now, in our continuation of this example, we will develop another function whose name will be called changeboard header names, so we will continue by defining the new function called changefunction. change board header names so this change board header names will be the new feature for us and here they would like to check if the user is winner or not so here we say if not winner then, In that case, we have to say leave player. text equal to point query selector document in this you will get the details like point board and here we will give the name called player and dash, turn player dash, turn now later, after this particular variable, we just have than check the condition by saying if current player is equal to x if position is x sorry let me try to capitalize here go to multiple lines, that's the benefit of this backtick and here we say in our internal html extension class equals name script script style close this and here we want to use the declaration now this value we want to write it with name attributes, so which is coming up and here we're saying dollar with this player x point name and then we close the span tag and say you're up like this and then we say class div equal to which will create a class that we can then apply the CSS style to the top of that script u script r script winning and here we say close the div tag so that the dip tag is closed that's it and now after this line the next thing we have is called one more condition what else here we say current layer text dot internal html html internal equal to after this we will write the extension class equal to here we say name script script the same option we are going to use in this condition, winning conditions, so let me try to copy the same instead of copying it again and again, I'm just going to copy the entire text, expand class equals name, hyphen, iPhone player style instead of saying x, you can use the file, you're up, you're the winner, okay, so here it will close long after this, what we could do is create another function called reset. port function reset board now in this reset board function we just say console.log a small message is added reset reset now then we will use the game board and the same game board that we have used before.
I'll use the same conditions at the top, if you remember, that was the game code for me, so I'll use the same keyboard, let me copy this, yeah, with the same condition, okay, give me equal to this, after that line we will say let sell to add a symbolic cell to add a token equal to the document point query selector, all here in this I will use another class called letter now cell to add a token, whichever we have used the point for each square and inside from this square we would like to use a square dot text content equal to black after that square dot parent element point class list dot delete and here we would like to say dash okay underscore underscore cell winner so we had to create these classes because these changes the classes were just using this but we have not created, we will be using it later, that was the point now, after that we are defining the value of the turn, turn equal to zero because we are restarting it and winner equal to false, after that winner equals false, we simply define another variable, we define it as current player text. text equals document dot query selector all yes document query select all so here we will use name called board define player dash dash rotate after that current player current player text current player text dot html inner equal to once again we have I have to use the condition for up and winner point, so let me try to copy this internal html equal to "ok" and in this we have to say player x point name "ok", everything is the same, without any changes, okay, now , after that we will write one more function called function add cell click listener that means when will I add or click something in my cell what kind of event would I like to listen here we are saying constant cells equal to selected document point query let's all check the condition board dashboard cell and here once again we say stop cell for each point for each and here we say add cell point event listener, what event I want to listen to, click and the second parameter will be the controller in call, make move, okay and this function that we created is called add cell click listener, okay, I'll call it here perfect later once it's done. try adding one more function called function remove click listener from cell remove click listener from cell now here we say all cells equal to document point selector all let's pass the dash cell and now we say all the sets of points for each cell and here we say remove the point from the cell event listener, what click event and second parameter will be created, that's all friends, now, most of our

javascript

code is written now, so in the future we would like to use css and eventually we will apply everything in our html file long after

javascript

.
The file is ready for my application, now it's time to create our html file. Sorry CSS, so inside my tick I have app.js and index.html ready. Now here I'm going to create another file called application. css, look, you can basically put this app.css in any folder, like in a static folder, but I've kept it out from this point on. I would like to start with my basic functionalities. Well, what are they? Let's start with the first feature called modding. with my body some basic settings I would like to make like in the background image background color so I just start with the background color background color I can use it as white okay but I don't think so it really needs it so if you want Otherwise, you can make it leave this background because by default it will be just white and now the next one will be called height.
The height will be 800 pixels. The next position of the fund. Bottom position. I'm just saying as a center. The following background repeats in case you don't want it. repeat image background repeat and here I say no repeat next background size here using cover okay resize the background image to cover the entire container okay so that's the part of the body, now the next thing is that we have to select the rest of the CSS classes. so first select the relative div point inside this data, the alternative is to first say the call position, we say absolute, then it is stop from above, I am just doing 760 pixels, the next right says 120 pixels, after this, we say height of thecontainer, height point container or sorry hide dash container here in hide dash container we will show show colon none after that we have to use header dot header inside this header we will say color will be white by default , but we still just say color and white in the next text line we just say center next margin the margin will be 50 pixels next font family font family I'm selecting permanent marker called permanent marker permanent okay, next class we're talking about calling the interlocutor called dot enter dashes players now a player between dashes for the sake of color Once again, we can use another clear, but we can use white or any color you want or you can just use hash, okay, the margin margin that we are giving it is called zero autowidth.
We are looking forward to the next core position of the 80 texture line right now. next we go forward for the input field in this input field we just say border border two solid black pixels next outline outline none I don't want there to be any outline there next fill can I take four pixels eight pixels four pixels eight pixels now margin we are saying 0 0 10 pixels is fine and finally for the pixels after this margin we say font size 18 pixels is fine so that is your input field next we are talking about something called input field focus input dash field okay two dot focus now here border two pixels solid on the right or whatever other color you want to use next how do you want the submit button to be so I say dot, dash, btn, border, two pixels, solid and black , adding 8 pixels and again 8 pixels, font size 80 pixels now with 250 pixels followed by border radius 5 pixels next to its margin from above let's take 10 pixels after that background color let's take just white, okay then this is the property that you can now associate with your active submit button and the submit button focus, so we say point submit dash between two active points and two options that we're taking followed by a condition outline, then the next edge we're talking about 2 solid pixels and the red color is fine, so that's the one we like to use about the dot send dash button two dots about what you want change the background color to white, you can use white smoke, well, here we like to use a dot board, here we would like to use a player script, so these are the classes that we were using in our javascript, we remember and here say color color that we are using once again, right, or you can use this smoke white, whatever you want, later, align text, center margin, 10 pixels, 0 and 10 pixels, height, 54 pixels, okay, these are the properties that we have initially taken, okay, then this turn, let's go and let's start other classes here I am saying point name dash style dash and here we are saying color red and then font size 22 pixels well now coming back to the other properties now we are talking about a next important one called border container called board container container ship points here we define the width which is 40 pixels we are taking or sorry 40 percent we can take after that background colors we can say blue coded okay next margin we are taking is 0 and auto after from that font size font size we are taking 0 next border bottle we are taking two pixels, then solid and then black followed by the box shadow.
Remember that this worksheet is one of the popular properties of season three. Here we are defining three pixels three pixels three pixels zero pixels and rgb we can talk about calling black okay so my border color will be the shading color after that we are offering this dash cell point now in this cell of the board we are defining the width now in this width we are using the ca lc calculation and in this calculation we are defining 100 percent right, divided by three, this calculation after this, the next property will be display the screen will be an inline block, the next font size we are taking 40 pixels and the center border of the texture line we are taking two solid black pixels. adding 20 pixels vertical alignment up next font family this formula can use permanent permanent marker okay, now next option a part of this we have a call to your board circle board cell no spelling mistakes this has to be d yes for cell let's make the background color be red, okay and then just use letter now in this letter we only give the color combination so that the color is white the next position relative to the upper fifty percent next transformation translate and to minus 50 after that font family the we are doing once again permanent marker let me copy okay now, here the next option will be called winner container.
Here we give winner with dot, dot, dash, winner container. Okay, so for this winner container, what are the values ​​that we want to use? Basically, you want to do it. For this winning container, what would I rather suggest that you can use the center margin of the dot reset texture line which is for reset and now reset hidden inside this reset header we will set the display name that none is displayed, then of this, the play button, yes, I'm going to talk about the repeat button. play the vta script and here we get to 25, okay and followed by a 10 pixel fill, we take it from here and the 20 pixel border, this bottle that we are taking is called 2 pixels, followed by a solid color, okay and black, now later on the border radius, border radius. we are taking 5 pixels later in the outline I say none after this outline we say letter spacing now this letter spacing would again be 0 after that text transform this text shape value we are talking about called uppercase next font size font size we We are taking 16 pixels, then the top margin the top margin would be 12 pixels, then the word spacing is taking three pixels followed by the background color.
This is taking white as usual, so this is for the play button. Okay now in a similar line we can also have call dot replay iphone btn colon hover followed by dot replay active script now apply the common style scheme we are making it null so the color we are creating is called white then the color of background will be black okay and when it comes to congratulations we will We will be using this dot okay so this congratulations class will use a font size of 24 pixels and after this we will use this call winner dot u dash r dot winner in this winner we will take a font size, okay, that's 18 pixels after that height.
We're taking 18 pixels again, then the line height, the line height, we're taking 18 pixels and then a margin of two pixels and then zero, okay, that's it. Last but not least, we would like to use this point repeat script, but I say this with 50 50 percent. This is what my CSS file is set to. I know it was quite long, but it is necessary for this particular application. Okay everyone, we are ready with our CSS. Now it's time to go back to our index.html file and take care of it. the final finishing touch so that we have this index.html file with us and now the css class that we were using in our application which is known as calling this permanent marker.
This class is not available by default, so we have to include it using this. external api so here where we have a css call with us before we want a link, inside this link we want our variable name to be called href equal to now we have to give the proper location by saying https colon double slash sources dot google apis okay dot com slash css question mark family equals permanent marker plus okay, so if you just copy this into your browser, you'll know exactly where it's used. Okay, if I just copy and paste it, I just need to say https before yes, https. fonts dot google apis dot com slash oh misspelling css family equals permanent marker which is the main URL from where I can grab this type of font so here css so that's what I was checking well there it is we've also including our css but in which class we need to use that is important now js.
I also want to include it, so here in my main tag I would just like to include the script src equals app.js, so here my script actually loads now after that, if I just go back and check the final result of my code, which is index.html5. Well, it seems that in principle nothing else has begun when we talk about calling the start of the game. Okay, so you need to get started because there is no CSS class attached to it. so I need to attach those classes inside my code, so from now on we have to start offering those CSS classes so that I can at least apply those common behaviors to my application.
Okay, here we have a calling div to which we haven't attached any classes. this after this body we have a tip part class h1 equal to header noughts and crosses then we have a div call we have a call body below this we have a call another div tag so imagine how many types of classes are available one we have the class tip call equals to header the div class closes again we have a call to one more div tag so there are several css files where we have to apply the new css class to make this happen so now we just have to go back and change . our html and apply our main class, so this is my final html, which looks the same.
You can see that we have added all those types of CSS classes that we had and they are called inter player player, player, container, tag, placeholder and player container and If you see all the different types of classes, we have attached this because here only will apply my CSS class and JavaScript will apply that type of dynamic CSS based on certain conditions, so these CSS classes are already added inside your HTML page. app css is ready app.js is also ready now let's go back and try to reveal how it looks amazing so that it looks quite nice tic tac toe is a game that is waiting when it says start game it says that you have to enter a name for each validation field it is working , let me try to add two names and say start game awesome, so now you can see it says "you're awake now", let me try to give the values ​​awesome, now you can see it says "hey you". you are a winner great so guys congratulations on this the first example of how to use the tic tac door game so it is a classic example of css, javascript and html together so this time we will talk about our next very interesting feature which is called deal with Another example which is called snake game so stay is one of the most powerful example which I am going to share with you which will help you understand how we offer the simplest way to develop a mini project.
Well, that's something. which is a snake game, let's see how important the snake game is and how we are going to deal with it. These are our previous examples that we have seen, which I will call a project that we have created and that is called test application and now We are going to start working with our new project now here, first of all, I am going to create a new folder that is called snake again and inside this is a game. We need some new folders. I'm going to create the first folder inside this. that is called images and inside this snake game I am going to create some new files which are called index dot html and here I am going to create a new file name called app dot js at the same time I will have some of the css files if I need them, I can say app dot css so I have a total of three files now let me close all the files any that I have opened before so now it looks like a cleaner approach so this is the snake game for us from where we need to get started and we have called the file index.html and here I think it will create our basic html syntax and here I would like to include our script tag script src equals app.js that's it and now we go ahead we will start developing our next implementation of snake now inside my body tag.
I would like to have some basic property called speed, okay and later I will take the input from the client, so we say the input type is equal to, so here we can justify the speed and we can give an id equal to the speed of the game and followed by a value equal to we can give the value. called 5 initial value and min equal to 1 which is the minimum value and max equal to 9 which is the maximum and minimum value that we can offer beyond that I will not allow users to go and take a step which means the increment value that It's a good one, that's the type of entry and now another entry, we're taking thethis condition called snake and snake and double equal to minus one, so we are giving this call minus one or white snake equal to the height of the game area save it or here we will take another condition here yes, we will take another condition here called we will have another function called control that we have created some time ago and inside this control it will take some parameters, so what? we can pass those parameters and we can say snake x comma snake y comma the third parameter will be snake so this could be my other function okay here we are passing the conditions like this okay now here this is available to use a parenthesis and here we are writing the situation for the correct score, which until now the function is only created, it is not described further, so we are writing the correct score, the score will be written here and here we say clear interval because the stopwatch will stop , okay and using game start point disabled equals false and then return that's it so this is the logic for what we have written in this particular example now we can use another one if there are more conditions here just to check the behavior of my code if starting to learn it is half the battle, what if you could do that for free?
Visit skills by simply learning, click the link in the description to learn more. We're done here until this game starts. Point disabled equals false and we return now, moving forward after this return. we would like to have another condition for snake x, so we say if a snake x if a snake x is double equals snake food dot the snake food, period y, so in this case I will say var new head bar new head sorry var new head equal to here x colon snake x y colon snake boy snake x e y colon snake and these options we are taking it now, after that, we use this option called player score plus equals speed size and then we call create food method again and then we use else condition and in this else condition we say var new head equals snake point pop okay and we are saying a new head point x equals snake and moves. and here we are passing this option called new head, that's it and after that we will start with our for loop by saying for var equal to 1 i i equal to 0 so i is less than the length of the snake point and the length of the point of the snake and once i plus plus ok later we just use the option called create square and in discrete square we are passing snake snake position i dot text comma same snake dot and that's it so it closes here and after that we call the same option with this snake foot, let me copy this again and here instead of using this, we can say snake food point x and snake foot point y, okay, now these values ​​have been added to my code, Now let me start working with your control.
The control needs to take three parameters x and y. and the array so we are passing this option called control and in this control we are taking x comma y comma array three parameters which we will take later we are using this option called var i equal to zero i is less than the length of the point of the array and i plus more and after that we will use this option called if condition and here we say matrix i whose value you are passing dot x double equal to x percentage of time of the ampersand here we say matrix with a position called i and in this we are saying dot y and in this position we are checking the condition and for the condition and so it returns what is true it returns true the condition is ok that is for if the condition otherwise it returns false that's it now we are talking about this name option called write. get this score right we have to use game area context game area context point source equal to here we will pass this situation we are saying 50 pixels 50 pixels and then cell script service after that we are using context from game media call again let me copy this, take it again, call game area context point fill style equal to here.
I'm going to use another color now, so we say hash, okay, now after that we say once again the game area context dot fill text here we are saying. score two points and here we say plus player score, whatever with play area width, play area width, slash 2 minus 100 and then again slash play area, so this is exactly where will write exactly the correct punctuation where the data will be written. Okay, so next having this option called create square on this big square it takes two parameters, one we're talking about is calling x second, it's taking y and now here we're using the play area context, same point fill style. same to let me give the color after this we are using call the same gary and text play area fill text point react here we are saying x multiply by cell with comma and multiply by cell width cell width comma cell weight comma this is what my rating square is now we are only left with one option which is known to change direction, it's time to discover this last function called change direction, which takes a parameter called e, we usually talk about parameters, now here we are passing this option called work keys equal to e dot and later we want to say if the keys are equal to 40, okay, ampersand, ampersand, snake direction equal to up, okay, here we say that the snake direction is equals tau so we're changing the addresses here okay now let me try to copy this and here we use elseif four times okay so here we say this 30 40 and here we say 39 followed by 38 followed by 37 39 38 27 and here we say up let's change to what was left down here we say right up left three options that we have changed and last but not least here I will just use the window point on the down key equal to change direction and the window point on loading, okay, it's equal to initialize, this is exactly how we want to use it now and this function is what we have defined in initialize, okay, so in this initialization we have this starting point of the game. clicking and everything so that you have a call to start the game now this start game will call it here okay so at startup they called us snake we have called snake point push and after that we call this function called what create interval of food cleaning and here let's say a timer equal to here let's set a clear interval and here let's change the size of the bar speed of the game area let's say you want to use it okay everyone our code is almost ready so we have this Complete javascript code ready with me, now it's time to basically use it inside my html. just to check how it can behave, in my html page I have written this normal speed number, game speed value, start button, we will call the game start, after that we have a call canvas where we write an id equal to call to the game area dev classic a relative and that's it and here we have a script calling sr equals app.js so that's what we have written now finally we would like to see how it would look if I try to use it in my browser let me try updating, okay?
I don't really see any change in my code, it's okay, even though I have this because actually the CSS content is missing, it's okay, because only there my code really looks better because if there is no CSS, it really wouldn't be good for me application. and I also want to have certain images, but we will take those images later. Let me go back and try to incorporate CSS into this image now, so first of all, have this index.html file with me and here I want to use CSS. inside my main tag we want to use a real link equals style sheet okay hr equals app dot css okay now here in my CSS we want to offer certain details that I want to start working with.
I'll start with my body part. then we want to offer the font family, so the font family can be a little bit later. I can use it first. I want to use margin margin 20 pixels automatically then align the text to the center next font size font size 150 pixels also 150 and here we want to say background background image since I don't have any image so I will leave it blank okay , otherwise I have to say URL and insert this URL. It gives some values, but I leave it blind because I don't have any images. I will say background color, this background color, I can use white after that height, I can say 800 pixels after that background position, background position, I want to use center and then repeat background, repeat background, I don't want to repeat , then the background size, okay, let's see if there's an effect on my okay, I see now it's in the middle, better now, input canvas, basically we have to take that here we're just talking about call input, okay , in this entry I say font size, font size can be optional, I can do it, but let me. say font size 100 percent then align the text in the center and then fill i mean 5 pixels and 7 pixels ok now it looks better well after that i can use canvas in this canvas i want to see background color only I say white after that border radius order is, I can say 20 pixels and then shadow if I want to use it, so I just say shadow box shadow box I can say 3 pixels, 5 pixels and 6 pixels and the color is black, let's see awesome so you can see here the logic is there, so you can easily see how it has been used and that's it and this div I can say relative position of the div point above absolute here I am saying it uses 760 pixels, 120 pixels left, that's all , so this is exactly where I program now when I say start ok, so there may be some error here, so they can't set a call on click property to null, so we can check this in this uh gamestop.onclick, let's check again anyway, we're just trying to fix that problem in the meantime, but anyway we have our CSS created and now in the future we'll implement the rest of the logic inside my code, okay everyone, so we changed some names here because there was some value that didn't it matched so basically we change those values ​​with its properties and now when I try to restart my application with this index.html file so now in my index.html file when I try to add it's as usual same thing let me say start and here you can see the start of the game when I go up, you see it's starting right now.
Well, isn't this an amazing game right now? Friends, it's okay, it's the same game you used to play before. Well, but you can change the direction, go up and you can see that the score 10 has been placed here, that's it, so this is it. where exactly the look of your game has been taken and uh you can just increase the speed, let's say if you just put a value, call zero by default, set whatever value you want to take with a start, now you can see based on that. the speed can be justified and the example can be developed.
Well, you can see that the home button is disabled because at this time the user continues, unless the user's game is over, this will not work well, so you can see and automatically this will be the position, this is what called food, this is how we have used it in my example in app.js. You can see that we are using this example name called food, create food, so when creating food in the specific time interval, this would be automatically. created and the snake will eat and increase the code size, okay that's it and now the CSS has been provided, if you want to add a certain image you can certainly add it;
Otherwise, this is the first game that we can see how it is run and giving it the best example and with that we have reached the end of this video. I hope you had fun creating these apps. If you have any doubts or queries, let us know in the comments section below. Thanks for watching, keep learning and stay tuned. for more of cynthia you

If you have any copyright issue, please Contact