coding 101: a hands-on introduction

33
CODING FOR LIBRARIANS PART 2: CODING 101 HANDS-ON INTRODUCTION Bohyun Kim Associate Director, Health Sciences & Human Services Library University of Maryland, Baltimore Reaching Across Illinois Library System - Webinar Tue, May 31, 2016 1:00 PM - 2:00 PM CDT

Upload: bohyun-kim

Post on 12-Apr-2017

350 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Coding 101: A hands-on introduction

CODING FOR LIBRARIANS

PART 2: CODING 101 HANDS-ON INTRODUCTION

Bohyun Kim Associate Director, Health Sciences & Human Services Library

University of Maryland, BaltimoreReaching Across Illinois Library System - Webinar

Tue, May 31, 2016 1:00 PM - 2:00 PM CDT

Page 2: Coding 101: A hands-on introduction

WHY ARE YOU INTERESTED IN CODING?

• Q. What do you want to be able to do once you learn how to code? 

• Q. Do you have previous experience with coding, and if so what is it?

• Q. If you tried to teach yourself how to code before, what were some of the difficulties?

Page 3: Coding 101: A hands-on introduction

Flickr image: https://www.flickr.com/photos/nathansmith/4704268314

Page 4: Coding 101: A hands-on introduction

WHAT IS JAVASCRIPT?• JavaScript is a cross-platform, object-oriented scripting

language. It is a small and lightweight language. Inside a host environment (for example, a web browser), JavaScript can be connected to the objects of its environment to provide programmatic control over them.

• JavaScript contains a standard library of objects, such as Array, Date, and Math, and a core set of language elements such as operators, control structures, and statements. Core JavaScript can be extended for a variety of purposes by supplementing it with additional objects;

• https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Introduction

Page 5: Coding 101: A hands-on introduction

JS

• Default scripting language for the Web. • Runs in a browser!• Minimal dev environment setup

Page 6: Coding 101: A hands-on introduction

SET-UP

• A computer with access to the Internet• Web browser • Firefox • Web Console (

http://www.howtogeek.com/105320/how-to-use-firefoxs-web-developer-tools/)

• Or, Firebug: https://addons.mozilla.org/en-US/firefox/addon/firebug/

• Or, Chrome • Devtools (https://developer.chrome.com/devtools)

Page 7: Coding 101: A hands-on introduction

LET’S TRY RUNNING A SCRIPT!

• Open up your web browser – FF or Chrome.• Press F-12 to open up a browser console.

Page 8: Coding 101: A hands-on introduction

FF – WEB CONSOLE

Page 9: Coding 101: A hands-on introduction

FF- FIREBUG

Page 10: Coding 101: A hands-on introduction

CHROME - DEVTOOLS

Page 11: Coding 101: A hands-on introduction

TYPE THIS IN & RUN IT!

var a = ["do", "re", "mi", "fa"];var len = a.length;for (var i = 0; i < len; i++) {

console.log(a[i]);}

Page 12: Coding 101: A hands-on introduction

• Result should look like this. FF above. Chrome below.

Page 13: Coding 101: A hands-on introduction

SUCCESS? : )

Don’t worry yet about what it means.

We will take a look again at the end of this workshop.

And it will all make sense then!

Page 14: Coding 101: A hands-on introduction

1. VARIABLES• 4+10• 2*5• var a=24/4;• a• console.log(a);• var b=“Catherine”;• console.log(b);• console.log(c);• a+b • a+3

Page 15: Coding 101: A hands-on introduction

VARIABLES & OPERATORS

• http://www.w3schools.com/js/js_variables.asp

• http://www.w3schools.com/js/js_operators.asp

Page 16: Coding 101: A hands-on introduction

2. DATA TYPES

• Number• String• Array• Object• Boolean

Page 17: Coding 101: A hands-on introduction

DATA TYPES

• http://www.w3schools.com/js/js_datatypes.asp

Page 18: Coding 101: A hands-on introduction

3. FUNCTIONS

Page 19: Coding 101: A hands-on introduction
Page 20: Coding 101: A hands-on introduction

FUNCTIONS

• http://www.w3schools.com/js/js_functions.asp

Page 21: Coding 101: A hands-on introduction

4. ARRAYS

• http://www.w3schools.com/js/js_arrays.asp

Page 23: Coding 101: A hands-on introduction

MORE ARRAY METHODS

Page 24: Coding 101: A hands-on introduction

DID WERUN OUT OF TIME

YET? : )

Page 25: Coding 101: A hands-on introduction

6. FOR LOOP

var a = ["do", "re", "mi", "fa"];var len = a.length;for (var i = 0; i < len; i++) {

console.log(a[i]);}

Page 26: Coding 101: A hands-on introduction

FOR LOOP

• http://www.w3schools.com/js/js_loop_for.asp

Page 27: Coding 101: A hands-on introduction

7. STRING

• http://www.w3schools.com/js/js_strings.asp

Page 28: Coding 101: A hands-on introduction

8. METHODS FOR THE STRING OBJECT

• http://www.w3schools.com/js/js_string_methods.asp

Page 30: Coding 101: A hands-on introduction
Page 31: Coding 101: A hands-on introduction

MORE CODE EXAMPLES BY ME WITH EXPLANATION• The simplest AJAX: writing your own code (1)

http://www.bohyunkim.net/blog/archives/2186• More APIs: writing your own code (2) http://

www.bohyunkim.net/blog/archives/2219 • Playing with JavaScript and JQuery – the Ebook link HTML string generator and

the EZproxy bookmarklet generator http://www.bohyunkim.net/blog/archives/255• Fear no Longer Regular Expressions http

://www.bohyunkim.net/blog/archives/2595 • Using the Stripe API to Collect Library Fines by Accepting Online Payments http://

www.bohyunkim.net/blog/archives/3009 • More simple code examples at https://github.com/bohyunkim/examples

Page 32: Coding 101: A hands-on introduction

TIPS

• Don’t be discouraged or frustrated. You are teaching yourself a language.

• Be persistent and realistic.• Set small goals that solve real-life problems.• Form or join a study group & find like-minded folks!• Comment your code and document since you will forget what

you have learned and made.

Page 33: Coding 101: A hands-on introduction

THANK YOU!