Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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

Arrow left icon
Profile Icon Omar Faruk Towaha
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5 (2 Ratings)
Paperback Jan 2016 188 pages 1st Edition
eBook
$15.99 $22.99
Paperback
$27.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Omar Faruk Towaha
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5 (2 Ratings)
Paperback Jan 2016 188 pages 1st Edition
eBook
$15.99 $22.99
Paperback
$27.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$15.99 $22.99
Paperback
$27.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781785287176
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 93.97
Raspberry Pi Projects for Kids (Second Edition)
$26.99
Python Projects for Kids
$38.99
JavaScript Projects for Kids
$27.99
Total $ 93.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.