Learn to Code With JavaScript
130 pages
English

Vous pourrez modifier la taille du texte de cet ouvrage

Découvre YouScribe en t'inscrivant gratuitement

Je m'inscris

Learn to Code With JavaScript , livre ebook

-

Découvre YouScribe en t'inscrivant gratuitement

Je m'inscris
Obtenez un accès à la bibliothèque pour le consulter en ligne
En savoir plus
130 pages
English

Vous pourrez modifier la taille du texte de cet ouvrage

Obtenez un accès à la bibliothèque pour le consulter en ligne
En savoir plus

Description

A hands-on, practical Introduction to coding!


Do you want to learn to code? Perhaps you want to learn how to build the next social media sensation or blockbuster game? Or perhaps you just want to get some valuable coding experience under your belt? This easy-to-follow, practical, and fun guide is the perfect place to start on your coding journey. You'll be learning to program with JavaScript - the most popular programming language on Earth. And it runs in web browsers, making it particularly suited to creating web-based apps and games. But the principles and techniques that you'll learn will provide you with a foundation to go on and learn many other languages, too.


You'll learn:


  • Programming basics, including data types, variables and more
  • How to use logic to control the flow of a program
  • How to use loops to repeat code over and over again
  • How to write functions that can be used to store code in reusable blocks
  • How to store data in collections such as arrays, sets and maps
  • How to create objects that store properties and actions
  • And much more!

Along the way, you'll build a collection of fun applications, including games and interactive web pages. Start learning to code today!


Sujets

Informations

Publié par
Date de parution 16 mars 2021
Nombre de lectures 5
EAN13 9781098124786
Langue English
Poids de l'ouvrage 2 Mo

Informations légales : prix de location à la page 0,1450€. Cette information est donnée uniquement à titre indicatif conformément à la législation en vigueur.

Extrait

Learn to Code with JavaScript
Copyright © 2021 SitePoint Pty. Ltd.
Ebook ISBN: 78-1-925836-41-7 Product Manager: Simon Mackie Technical Editor: James Hibbard English Editor: Ralph Mason Cover Designer: Alex Walker
Notice of Rights
All rights reserved. No part of this book may be reproduced, stored in a retrieval system or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews.
Notice of Liability
The author and publisher have made every effort to ensure the accuracy of the information herein. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors and SitePoint Pty. Ltd., nor its dealers or distributors will be held liable for any damages to be caused either directly or indirectly by the instructions contained in this book, or by the software or hardware products described herein.
Trademark Notice
Rather than indicating every occurrence of a trademarked name as such, this book uses the names only in an editorial fashion and to the benefit of the trademark owner with no intention of infringement of the trademark.

Published by SitePoint Pty. Ltd.
48 Cambridge Street Collingwood VIC Australia 3066 Web: www.sitepoint.com Email: books@sitepoint.com

About SitePoint
SitePoint specializes in publishing fun, practical, and easy-to-understand content for web professionals. Visit http://www.sitepoint.com/ to access our blogs, books, newsletters, articles, and community forums. You’ll find a stack of information on JavaScript, PHP, design, and more.
About Darren Jones
Darren has enjoyed coding since learning how to program in BASIC on his first Acorn Electron computer. Since then, he’s taught himself Ruby and JavaScript and is the author of JavaScript: Novice to Ninja and Jump Start Sinatra . He also produced the “ Getting Started With Ruby ” video tutorials for SitePoint Premium and has written a number of articles on the SitePoint website. He was born in the city of Manchester in the UK, where he still lives, and he teaches Mathematics and Computing at a local high school. You can find him on Twitter @daz4126 .

Preface
I still remember my first ever computer: it was an Acorn Electron, and I loved using it to play games such as Sphinx Adventure (a text-based adventure), Starship Command (a hard-as-nails shoot-em-up) and Chuckie Egg (pure platform action). But the real fun started when I realized that I could write my own code in a language called BASIC. My initial thoughts were that it had been named ironically, as it appeared to be anything but basic. It had line numbers that went up in multiples of ten and strange-sounding commands such as GOTO , REM and CLS that just looked like gobbledygook at first. But with lots of practice (and many mistakes), it started to make sense and I became fascinated by how the code allowed me to control what the computer did. I would spend hours copying code examples out of magazines (yes, it was that long ago!) and then play around making my own modifications. It was this experimentation and tinkering with code that helped me understand how it worked. I had been well and truly bitten by the coding bug.
My enjoyment of coding comes from the fact that it requires you to follow the precise rules of the programming language while also encouraging you to think creatively to achieve your desired outcome. The essence of coding is turning the abstract into the practical. When I set about writing this book, my aim was to introduce the basic concepts of coding and back the theory up with plenty of practical examples. Each chapter ends with coding challenges that will help consolidate your understanding. I encourage you to really dig into these challenges by not only trying to complete them, but also trying to extend them with your own modifications.
It was always games that I wanted to program, and I’ve tried to make as many of the challenges in the book as fun as possible, both to code and to play. And by the end of the book, you’ll have coded a couple of fully playable games. You’ll also have the foundations in place for creating interactive websites and be on the right path to writing full-scale applications.
Programming is a creative endeavor; it’s fundamentally about creating things. You need your code to be precise and concise, but you also need to inject it with some flair to make it come alive. This mix of precision and ingenuity is what continues to make coding enjoyable for me, many years after starting out on my Acorn Electron. My hope is that this book will inspire you to start coding and that you’ll continue to enjoy it for a long time after you’ve finished reading the last page.
Who Should Read This Book?
This book is for people with no prior programming experience who would like to learn how to code. We use JavaScript in this book to teach you, so at the end you'll have a good understanding of JavaScript, but you can apply the principles you’ve learned to other programing languages, too.
Conventions Used
Code Samples
Code in this book is displayed using a fixed-width font, like so:
<h1>A Perfect Summer's Day</h1><p>It was a lovely day for a walk in the park.The birds were singing and the kids were all back at school.</p>
You’ll notice that we’ve used certain layout styles throughout this book to signify different types of information. Look out for the following items.
Tips, Notes, and Warnings

Hey, You!

Tips provide helpful little pointers.

Ahem, Excuse Me ...

Notes are useful asides that are related—but not critical—to the topic at hand. Think of them as extra tidbits of information.

Make Sure You Always ...

... pay attention to these important points.

Watch Out!

Warnings highlight any gotchas that are likely to trip you up along the way.
Supplementary Materials https://www.sitepoint.com/community/ are SitePoint’s forums, for help on any tricky problems. books@sitepoint.com is our email address, should you need to contact us to report a problem, or for any other reason.
Chapter 1: Press Start
So you want to learn to program? You’ve made a good decision. Programming is a fantastic skill to learn, and it’s great fun. It can be used to build the next generation of apps, hack a Raspberry Pi or Arduino, write the latest blockbuster games—and a ton of other things. In fact, once you learn how to program, the only limit is your imagination.
In this chapter, we’ll briefly survey the history of programming, look into what a computer program actually is, and then introduce the JavaScript programming language, which we’ll be using to learn how to program.
We’ll also be jumping right in and getting started with some programming, writing not one, but two programs in JavaScript!
Here’s what this chapter will cover: what programming actually is algorithms and pseudocode a brief history of programming an introduction to the JavaScript language “Hello, World!”—your first JavaScript program JavaScript in the web browser “I Can Code a Rainbow”—your second JavaScript program the mindset of a programmer
We’ll also finish the chapter with some programming challenges to help you to test your newfound skills—as we’ll do at the end of every chapter in this book.
Programming
Programming is about making computers do what you want them to do. A computer program is basically a series of instructions that tell your computer how to perform a task. Unfortunately, computers don’t speak the same language as us.
For example, you can’t just write “change the color of the circle to blue” and expect the computer to understand. A programming language acts as an intermediary: it’s a language that can be understood by both computers and humans.
Learning to program is a bit like learning a foreign language, except computers can be very picky about grammar (even more so than my French teacher was!). You need to make sure you get everything in the right place, and the syntax needs to be just right. Computers are powerful, and you can get them to do some truly impressive stuff, but they’ll also fall to pieces if just one bracket is out of place!
Writing a program is basically just writing a set of instructions for a computer to follow. The problem is, they have to be very precise instructions. Any slight ambiguity, and the computer will do something completely different from what you had in mind—or it might even crash.
Algorithms
The word algorithm is used quite frequently these days. You might have heard of the “Instagram algorithm” or the “Google search algorithm”. But what exactly is an algorithm? The word “algorithm” is a Latinization of the name of a Persian mathematician, Al-Khwarizmi, who wrote the first algebraic textbook and liked to explain his methods using a step-by-step approach.

This led to the word algorithm being used to describe any step-by-step method. It should be clear what to do at each step and what each step does. For example, here’s an algorithm for making a cup of tea: Boil water in a kettle. Get a cup. Get a teabag. Put the teabag in the cup. When the kettle has boiled, pour the water into the cup. Leave it to brew for two minutes. Take the teabag out of the cup. Get milk. Add milk to the tea. Stir the tea.

Milk after Tea

I realize my instruction to add milk after the tea is made might be controversial. If you think milk should be added first, I’m sorry, but you’ll just have to accept that you’re wrong on this one.
Those instructions seem fairly basic and straightforward, but there are quite a few assumptions made, and some steps are a bit ambiguous. How do you boil a kettle? Where do you get the cup and teabag from? How much water should I pour into the cup? These questions are left unanswered. This is usuall

  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents