Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
JavaScript Projects for Kids
JavaScript Projects for Kids

JavaScript Projects for Kids: Gear up for a roller-coaster ride into the world of JavaScript and programming with this easy-to-follow, fun, and entertaining project-based guide

eBook
€10.99 €16.99
Paperback
€20.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

JavaScript Projects for Kids

Chapter 2. Solving Problems Using JavaScript

You have learned how to print something using JavaScript on console in the previous chapter. Now, let's see the fundamentals behind JavaScript syntax, variables, arithmetic operators, and comments.

In the computer world, there is nothing but data. You can read, modify, and create new data; however, anything that isn't data simply does not exist. In JavaScript, we need to handle data to develop a website.

To understand the basic syntax of JavaScript, first of all you need to know that JavaScript is case sensitive. You cannot interchange lower case and upper case letters in JavaScript. Therefore, when dealing with the JavaScript syntax, you need to remember that writing the code is not the only important task, you must also watch the syntax whether it's written correctly.

Let me show you an example. In the previous chapter, you have successfully printed Hello World on your browser using the document.write(); syntax.

What would...

Variables

We already know that the computer world has nothing but data.

There are different types of data (we call them data types), as follows:

  • Your name is a kind of data
  • Your age is data
  • Your grade is also data

Yet, they all are different. What is the difference between them? Your name only contains a group of characters or, as some people also call it, string. Your age is an integer type data. Your grade is a float type data. The wonderful thing in JavaScript is that you do not have to specify the data type before writing a variable's name.

Note

JavaScript allows working with three data types. Strings (for example, "This is an example of string"), numbers (for example, 2015, 3.1415, and so on), and Boolean (for example, true or false).

Did we discuss variables? Well, you already know the data types. You will need something to store your data. This something is called variable. In JavaScript, we use var before the variable names. Remember that var starts with small letter.

Let...

Comments

Suppose you have done a lot of coding and some logical operations, and used a number of variables on JavaScript, and you want me to help you with the code if any errors occur. When you send me the code, I will not know what you have typed unless I have a clear knowledge of JavaScript or you have commented on the important lines.

A comment is basically a line of text or code that your browser ignores while running. You can compare comments to sticky notes or reminder.

Let's consider the following example:

Var name = "Sherlock Holmes"; // This is a string
Var occupation = "Detective"; // This variable stores information
Var age = 14; // This is an integer type of data.

How do you make multiline comments? You mention the comment in the following manner:

/*
  This is a multiline comment.
  The browser will ignore this.
  You can type any important information on your comment.
*/

Your multiline comment should be between /* and */, as shown in the following screenshot...

Arithmetic operators

In JavaScript, like other programming languages, we can do some arithmetic operations. In your school, you might have already learned how to add two numbers, subtract one number from another number, multiply two numbers, and divide a number with another. You can do all these things in JavaScript with the help of a few lines of code.

In JavaScript, we use the following arithmetic symbols for the operations:

Operator

Description

+

To add

-

To subtract

*

To multiply

/

To divide

%

To find the reminder (called modulus operator)

Addition

Suppose you have two variables, x and y, with the values 3 and 4, respectively. What should we do on the console to store the values on the variables?

Yes, we do the following:

var x = 3; // 3 is stored on variable x
var y = 4; // 4 is stored on variable y

Then, press Enter.

Take another variable that will hold the summation of x and y, as follows:

var z = x+y; // This syntax stores the sum of x and y on z

Can you tell me what will happen...

More operators and operations

JavaScript has more operators other than those stated earlier. Let's go little bit deeper.

Increment or decrement operators

If you have an integer and you want to increment it by 1 or any number, you can type the following:

var x = 4; // assigns 4 on the variable x.
x = x + 1;
/* since x=4, and you are adding 1 with x, so the final value is 4 + 1 = 5, and 5 is stored on the same variable x. */

You can also increment your variable by 1, typing the following:

var x = 4; // assigns 4 on the variable x.
x++; // This is similar to x = x + 1.

What will you do if you want to increment your variable by more than 1? Well, you can follow this:

var x = 4; // assigns 4 on the variable x.
x = x + 3; // Say, you want to increment x by 3.
/* since x = 4, and you are adding 3 with x, so the final value is 4 + 3 = 7, and 7 is stored on the same variable x. */

You can increment your variable by typing the following as well:

var x = 4; // assigns 4 on the variable x.
x += 3; // This...

Summary

In this chapter, you learned about the JavaScript syntax. We discussed the JavaScript variables and how to assign a value to a variable. You learned how to comment on the code. You now know why commenting is important. You finally learned an important topic: operators and operations. JavaScript, without using operators and logical functions, will not be so rich nowadays. Therefore, learning about the logical operations is the key to gain good knowledge of JavaScript.

I would like to suggest you to practice all the code in this chapter at home. You just type them on the console, avoid copying and pasting the codes. This will hamper with your learning. As a programmer must have a good typing speed, copying and pasting the codes will not improve this skill. You may face problems in typing codes; however, you will learn.

You can solve any arithmetic problem using JavaScript. You can also check whether your logic is true or false on console. If you can do this, we can move on to the next...

Left arrow icon Right arrow icon

Key benefits

  • Get to know the concepts of HTML and CSS to work with JavaScript
  • Explore the concepts of object-oriented programming
  • Follow this step-by-step guide on the fundamentals of JavaScript programming

Description

JavaScript is the most widely-used programming language for web development and that's not all! It has evolved over the years and is now being implemented in an array of environments from websites to robotics. Learning JavaScript will help you see the broader picture of web development. This book will take your imagination to new heights by teaching you how to work with JavaScript from scratch. It will introduce you to HTML and CSS to enhance the appearance of your applications. You’ll then use your skills to build on a cool Battleship game! From there, the book will introduce you to jQuery and show you how you can manipulate the DOM. You’ll get to play with some cool stuff using Canvas and will learn how to make use of Canvas to build a game on the lines of Pacman, only a whole lot cooler! Finally, it will show you a few tricks with OOP to make your code clean and will end with a few road maps on areas you can explore further.

Who is this book for?

If you've never written code before or you are completely new to the world of web programming, then this book is the right choice for you. This book is for kids of age 10 years and above and parents who are completely new to the world of programming and want to get introduced to programming.

What you will learn

  • Learn how to work with Google Developer tools to iterate, debug and profile your code
  • Develop a Battleship game using the basic concepts of HTML and CSS
  • Get to know the fundamentals of JavaScript programming
  • Create our own version of Pac Man game.
  • Discover the vital concepts of object-oriented programming

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 30, 2016
Length: 188 pages
Edition : 1st
Language : English
ISBN-13 : 9781783988495
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Jan 30, 2016
Length: 188 pages
Edition : 1st
Language : English
ISBN-13 : 9781783988495
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 71.97
Raspberry Pi Projects for Kids (Second Edition)
€20.99
Python Projects for Kids
€29.99
JavaScript Projects for Kids
€20.99
Total 71.97 Stars icon

Table of Contents

11 Chapters
1. Exploring JavaScript in the Console Chevron down icon Chevron up icon
2. Solving Problems Using JavaScript Chevron down icon Chevron up icon
3. Introducing HTML and CSS Chevron down icon Chevron up icon
4. Diving a Bit Deeper Chevron down icon Chevron up icon
5. Ahoy! Sailing into Battle Chevron down icon Chevron up icon
6. Exploring the Benefits of jQuery Chevron down icon Chevron up icon
7. Introducing the Canvas Chevron down icon Chevron up icon
8. Building Rat-man! Chevron down icon Chevron up icon
9. Tidying up Your Code Using OOP Chevron down icon Chevron up icon
10. Possibilities Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5
(2 Ratings)
5 star 50%
4 star 0%
3 star 0%
2 star 50%
1 star 0%
Towaha Apr 07, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Easy for not only kids but for new learners. Recommended.
Amazon Verified review Amazon
G. A. Patino Jul 11, 2016
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
A common complaint about many textbooks is that they start explaining everything very simply, but after a few chapters the level of complexity suddenly ramps up and the book leaves many readers behind. This book is a perfect example of that. I got it because, despite knowing some other programming languages, I wanted to learn JavaScript. The initial 4 chapters were great and provided a good introduction to the language, along with the key concepts of HTML and CSS. However, in chapter 5 the author basically posted the code for a version of the game Battleship stating what each portion of the code would do but not explaining how the commands listed achieved so. It might be possible for somebody with prior programming experience to intuit what the new commands and functions presented do, but if this is a book for kids I wonder how easy it is for them to achieve this if it is their first foray into programming. I was also looking for a good teaching text, not a demonstration of the things you can do with the language. Chapter 6 and 7 again do a decent job of introducing JQuery and the HTML Canvas, but chapters 8 and 9 are again just code listings (although chapter 9 offers a basic description of object-oriented programming concepts) for two other games without any explanations of the new functions or the Angular framework that are used. The first chapters of the book demonstrate the author's ability to explain concepts clearly and in a friendly manner, I hope that in the next edition of the book he keeps that spirit in all of the book's chapters.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.