Variables and Data Types

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

This is Java Jeopardy.
 Basically, it’s a sequence of characters.  Character? › Like… a letter. › Or a number. › Or even blank space (like spaces tabs and newlines).
 Basically, a sequence of characters  Character? › Like… a letter › Or a number › Or even blank space.
Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
Python November 14, Unit 7. Python Hello world, in class.
The Class String. String Constants and Variables  There is no primitive type for strings in Java.  There is a class called String that can be used to.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
JavaScript, Third Edition
JAVASCRIPT TIPS. REMEMBER JAVASCRIPT IS VERY, VERY CASE SENSITIVE.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
FUNCTIONS. Function call: >>> type(32) The name of the function is type. The expression in parentheses is called the argument of the function. Built-in.
2440: 211 Interactive Web Programming Expressions & Operators.
Operators, Functions and Modules1 Pattern Matching & Recursion.
Unit 3: Java Data Types Math class and String class.
Objects.  Java Script is an OOP Language  So it allows you to make your own objects and make your own variable types  I will not be going over how.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
ROUND 1 Name a method associated with class String 1.) 15 compareTo() 26 indexOf() 34 length() 2.) 3.) 4.) 3 toUpper() 7 substring() 11 charAt() 5.)
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
Primitive Data Types. Identifiers What word does it sound like?
Strings, output, quotes and comments
JavaScript Programming Unit #1: Introduction. What is Programming?
Variables and Data Types Data (information we're going to store) – Numbers – Text – Dates What types of data can JavaScript process? How do we store it?
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Two: Fundamental Data Types Slides by Evan Gallagher.
Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.
Strings The Basics. Strings a collection data type can refer to a string variable as one variable or as many different components (characters) string.
Introduction to LISP Atoms, Lists Math. LISP n LISt Processing n Function model –Program = function definition –Give arguments –Returns values n Mathematical.
JavaScript VARIABLES AND DATA TYPES. OUTPUT WITHOUT ALERT OR FORM CONSOLE.LOG();
Random Numbers. Are a series of numbers that have no pattern to them Ex) 7, 31, 4, 9, 8, 99… Random Numbers are used in… - Computer Games - Lotteries(6-49)
Creating and Using Class Methods. Definition Class Object.
JavaScript Functions. CSS Inheritance Which formatting applies? x y z input { display: block; } input.pref { background:red; } If you have a selector.
Expressions and Data Types Professor Robin Burke.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 4 – Simple Variable Types Modern JavaScript Design And Develop Copyright © 2012 by Larry.
 Collection of statements that can be invoked as a unit  Can take parameters  Can be used multiple times  Can call without knowing what they do or.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
ENGINEERING 1D04 Tutorial 1. WELCOME! What we’re doing today Who am I How to do well What are computer programs Software Development Cycle Pseudo Code.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
>> Introduction to JavaScript
Topic Pre-processor cout To output a message.
Formatting Output.
Loops BIS1523 – Lecture 10.
Introduction to Computer Science / Procedural – 67130
JavaScript functions.
Variables and Primative Types
JavaScript Functions.
JavaScript.
Introduction to Objects
Chapter 2 Basic Computation
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Console.
Using Objects 21-Nov-18.
Javascript: variables and parameters
JavaScript Functions.
Reviewing key concepts
T. Jumana Abu Shmais – AOU - Riyadh
Variables and Data Types
String and Lists Dr. José M. Reyes Álamo.
Wednesday 09/23/13.
CHAPTER 3: String And Numeric Data In Python
Appendix B.1 Lex Appendix B.1 -- Lex.
7 – Variables, Input and Output
Introduction to Computer Science
Introducing JavaScript
Unit 3: Variables in Java
Output Manipulation.
Exam Prep.
More Basics of Python Common types of data we will work with
What We Want To Do User enters: Mary Smith
Introduction to Objects
Presentation transcript:

Variables and Data Types JavaScript Variables and Data Types

WiLL CONNECT BACK TO HTML NEXT WEEK OUTPUT WITHOUT ALERT Console.log(); WiLL CONNECT BACK TO HTML NEXT WEEK

Holding information

Holding information Computer doesn’t understand values It knows about locations: “cubby holes” Takes locations and does what you tell it: read, write, add

A = B + C; example Cubby Hole 2: add this value Cubby Hole 3: place it here A = B + C; Cubby Hole 1: take this value

Defining CUBBY HOLES They are called variables Define them Give them values Take values from them

= means “takes the value of” A = B + C; A takes the value of B+C

Changing Information A = A + C; Cubby Hole 2: add this value Cubby Hole 1: replace the old value A = A + C; Cubby Hole 1: take this value

To DEFINE var anyName; Defines a variable called anyName Case-sensitive Can be any type of value var aNumber = 1; aNumber is a number Starts with a value of 1

VALUES

What values can it take? Any “expression” What is an expression? Variables Constants Operators functions Different for numbers and strings

Numbers Regular math operators Variables Constants Functions

Random Numbers

Why random numbers? Variability Different results Examples Display one of ten pictures Display one of five quotations Play a game of chance All built on a random number!

Can computers really create random numbers? Computers do as they are told So how can they do something random? They can’t! But we can tell them to find a number that changes often! Needs to not have an easily recognized pattern Pseudo-random Number Generator Options? Time!

Getting a random number Math.random() Returns a value between 0 and 1 One of a series of mathematical functions members of a collection called Math each are prefixed by “Math.”

What if you don’t want 0-1? Change range? Multiply Not start at 0? Add Integers only? Round Floor Ceiling

Strings Think of Scrabble tiles Each tile is a Letter Number Punctuation mark Space (blank)

What is a String? A literal string must be inside double quotes or single quotes “this is a string” and this is not a string. Remember to beware cut and paste

Concatenating (formally) It means combining two or more things into one thing + Anything can be concatenated “awe” & “some” = “awesome” Whitespace only matters inside quotes “a”+“b” same as “a” + “b” “a ” + “b” NOT the same as “a” + “b”

Substring A substring is also a String A substring is a part of another string “cake” is a substring of “birthday cake” so are “day”, “thd”, and “y cake” “they” is not, neither is “hello” or “dude” Will come back to how to extract substrings

Referencing characters Each character has a position Note that it starts at 0, not 1 H I M O 1 2 3 4 5