SlideShare a Scribd company logo
ALGORITHMS, COMPUTER GRAPHICS,
AND MATHEMATICS FOR GAME
DEVELOPERS & COMPUTER
SCIENTISTS
Class[2]: Introduction to JavaScript [Part 1]
PREPARED AND PRESENTED BY
Dr.Saajid Abuluaih, PhD
30th of May, 2021
Algorithms, Computer Graphics, and Mathematics
for Game Developers and Computer Scientists
© 2021 arche1.co.jp | jaist.ac.jp
All rights reserved.
2
Agenda
One-Bite Wisdom
JS Syntax: Variables & Operators
JS Syntax: Conditional Statements
𝑖
JS Syntax: Loops
Introduction to JS: Brief
JS Syntax: Functions
Today’s Algorithm
𝑔
𝑛
“The future is not just unwritten - it is unsearched”
-Bruce Sterling
© 2021 arche1.co.jp | jaist.ac.jp
All rights reserved.
P A G E 3
One-Bite Wisdom
RHIND PAPYRUS
4
ANCIENT EGYPTIAN MATH RIDDLE,
RHIND MATHEMATICAL PAPYRUS
References:
Math Puzzles’ Oldest Ancestors Took Form on Egyptian Papyrus
Episode Transcript – Episode 17 - Rhind Mathematical Papyrus
Rhind papyrus
In seven houses there are seven cats. Each cat catches seven
mice. Each mouse would have eaten seven ears of corn and
each ear of corn, if sown, would have produced seven gallons
of grain. How many things are mentioned in total?
(made around 3,500 years ago)
5
ANCIENT EGYPTIAN MATH RIDDLE,
RHIND MATHEMATICAL PAPYRUS
References:
Math Puzzles’ Oldest Ancestors Took Form on Egyptian Papyrus
Episode Transcript – Episode 17 - Rhind Mathematical Papyrus
Rhind papyrus
In seven houses there are seven cats. Each cat catches seven
mice. Each mouse would have eaten seven ears of corn and
each ear of corn, if sown, would have produced seven gallons
of grain. How many things are mentioned in total?
(made around 3,500 years ago)
The answer is as easy as:
7 + 72 + 73 + 74 + 75
Algorithms, Computer Graphics, and Mathematics
for Game Developers and Computer Scientists
© 2021 arche1.co.jp | jaist.ac.jp
All rights reserved.
WHAT THAT HAS TO DO WITH
OUR CLASS FOR TODAY?
NOTHING
it has nothing to do with today’s class
© 2021 arche1.co.jp | jaist.ac.jp
All rights reserved.
P A G E 7
Simple Algorithms
Let’s Brush our Coding Skills
Given a string, replace each its character by the next one in the English alphabet (z would be replaced by
a). Example: Example: “o`kdrshmd”, the output should be “palestine”
8
A SIMPLE ALGORITHM,
Alphabet Shifter
Given a string, replace each its character by the next one in the English alphabet (z would be replaced by
a). Example: “o`kdrshmd”, the output should be “palestine”
• Method [1] (Stupid):
9
A SIMPLE ALGORITHM,
Alphabet Shifter
function Alphabet_Shift(str) {
var dictionary = {
'a' : 'b', 'b' : 'c', 'c' : 'd', 'd' : 'e', 'e' : 'f', 'f' : 'g',
'g' : 'h', 'h' : 'i', 'i' : 'j', 'j' : 'k', 'k' : 'l', 'l' : 'm',
'm' : 'n', 'n' : 'o', 'o' : 'p', 'p' : 'q', 'q' : 'r', 'r' : 's',
's' : 't', 't' : 'u', 'u' : 'v', 'v' : 'w', 'w' : 'x', 'x' : 'y',
'y' : 'z', 'z' : 'a’};
var temp = str.split('');
for(var i=0; i<temp.length; i++){
temp[i] = dictionary[temp[i]]
}
return temp.join("");
}
Given a string, replace each its character by the next one in the English alphabet (z would be replaced by
a). Example: “o`kdrshmd”, the output should be “palestine”
• Method [2] (smarter solution):
10
A SIMPLE ALGORITHM,
Alphabet Shifter
function alphabet_char_Shift(str) {
var all_chars = str.split('');
for(var i = 0; i < all_chars.length; i++) {
var n = all_chars[i].charCodeAt() - 'a'.charCodeAt();
n = (n + 1) % 26;
all_chars[i] = String.fromCharCode(n + 'a'.charCodeAt());
}
return all_chars.join("");
}
console.log(alphabet_char_Shift("o`kdrshmd"))
References:
Look at the following solution to see how do they solve the ‘z’ letter.
© 2021 arche1.co.jp | jaist.ac.jp
All rights reserved.
P A G E 11
Introduction
What is JavaScript anyway?
The early to mid-1990s were a pivotal period in the history of the internet. Browser wars were raging
between major players like Netscape and Microsoft, with Netscape's Navigator and Microsoft's Internet
Explorer going head-to-head.
Due to the rapid growth of JavaScript, it became evident in 1997 that the language would need to be
properly maintained and managed. As a result, Netscape delegated the task of developing a language
definition to the European Computer Manufacturers Association (ECMA), an organization dedicated to
computer standardization.
12
INTRODUCTION,
BRIEF HISTORY
References:
The History of JavaScript: Everything You Need to Know
Netscape Navigator 2
- JavaScript was developed by NetScape to provide functionality to their internet browser in 1995
- Netscape handed the job of creating a language specification to the European Computer
Manufacturers Association (ECMA)
JavaScript is a scripting language designed for building interactive functionalities to websites. It is one of
the three most common languages for web development. Unlike HTML and CSS, which offer a website's
structure and appearance, JavaScript allows you to programs functionality and handle event behaviors to
webpages, allowing visitors to interact with page’s contents.
JavaScript is designed to operate on client-side. That means, the browser receives a copy of the source
code and runs it on the client machine within the browser environment. However, recently the
introduction of Node.js, JavaScript can now execute code on servers as well.
13
INTRODUCTION,
WHAT THIS COURSE IS ALL ABOUT
- HTML: is a markup language for
managing the contents
- CSS: cascading style sheet for styling
webpages contents
- JavaScript: programing language for
webpabes
- Most likely to be used as a Client-Side
Programming language
- JavaScript is an interpreter not a compiler
- JavaScript is a case-sensitive language
- JavaScript is a whitespace insensitive
- JavaScript has nothing to do with Java
© 2021 arche1.co.jp | jaist.ac.jp
All rights reserved.
P A G E 14
JavaScript
Language Syntax: Variables & Operators
The structure of delivering classes:
• Single line comment //
• Multi-lines comment /* */
15
JS SYNTAX,
COMMENTS
To store values, you can use variables. There are three primitive data types, and they are: Numbers,
Strings, and Booleans.
• Declare variables using var keyword, or the key word let (Homework: what is the differences between
them both?)
• You can use the const keyword to define variable that cannot be reassigned
var x = 5;
var y = 6;
var z = x + y;
const pi = 3.14;
let personFirstName = "Hiroyuki";
let personLastName = 'Iida’;
let personFullName = personFirstName + " " + personLastName;
var bool1 = true;
var bool2 = 11 < 10;
var arr = [true, 'true', 1];
16
JS SYNTAX,
VARIABLES DECLARATION & TYPES [1]
Objects is one of the most common variable types used in the language.
var car = {type:"Toyota", model:"500", color:"white"};
The Key:Value pairs in JavaScript objects are called properties
You can access object’s properties using the following two methods:
• car.type
• car["type"]
An object can have functions as well:
var car = {
type:"Toyota",
model:"500",
color:"white",
fullInfo:function() {
return this.type + " " + this.model + " " + this.color;
}
};
17
JS SYNTAX,
VARIABLES DECLARATION & TYPES [2]
Arithmetic operators are used to perform arithmetic on values of type numbers.
18
JS SYNTAX,
OPERATORS [PART 1]
Operator Description
+ Addition
- Subtraction
* Multiplication
** Exponentiation
/ Division
% Modulus (Division Remainder)
++ Increment
-- Decrement
Operator Example Same As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x - y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y
**= x **= y x = x ** y
Can you tell the difference of the following statements?
var x = 5;
x++;
var y = 6;
++y;
Comparison and Logical operators are used to test a statement to check whether it is true or false.
19
JS SYNTAX,
OPERATORS [PART 2]
Operator Description
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
? ternary operator
Operator Description
&& logical and
|| logical or
! logical not
Can you tell the difference of the following statements?
var voltage = (volt == 110) ? "low voltage" : "high voltage";
© 2021 arche1.co.jp | jaist.ac.jp
All rights reserved.
P A G E 20
JavaScript
Language Syntax: Conditional Statement
Conditional statement is a set of rules performed if a certain
set of constraints is met (IF a set of constraints is true THEN
perform the following rules).
if (Condition) {
statements;
}
if (Condition) {
statements;
} else {
statements;
}
21
JS SYNTAX,
CONDITIONAL STATEMENT [1]
Start
Condition
Execute the
following set of rules
End
Start
Condition
Execute the
following set of rules
End
Execute another set
of rules
True
False
False
True
Switch statement is used to perform a set of actions based on
different sets of conditions
var day = "";
switch (dayNum) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
default:
day = " undefined";
}
22
JS SYNTAX,
CONDITIONAL STATEMENT [2]
Start
Condition
Execute the
following set of rules
End
False
True
Condition
Execute the
following set of rules
False
True
Condition
Execute the
following set of rules
False
True
Execute the default
set of rules
© 2021 arche1.co.jp | jaist.ac.jp
All rights reserved.
P A G E 23
JavaScript
Language Syntax: Loop Statement
Loops used to repeat a specific block of code until some condition
is met.
for (i = 0; i < length; i++) {
statements;
}
You can move more than one step at a time.
There are the following loops that works with arrays and objects:
var obj = {prop1:"Hiroyuki", prop2:"Iida"};
var fullName = ""; var x;
for (x in obj) { fullName += obj[x] + " "; }
let arr = ["elm1", "elm2", "elm3"];
let text = "";
for (let x of cars) { text += x + " ";}
24
JS SYNTAX,
LOOPS STATEMENT [1]
Start
Condition
Execute the
following set of rules
End
True
False
Loops used to repeat a specific block of code until some
condition is met.
while (i < 10) {
text += "i = " + i;
i++;
}
do {
text += "The number is " + i;
i++;
}
while (i < 10);
25
JS SYNTAX,
LOOPS STATEMENT [2]
Start
Condition
Execute the
following set of rules
End
True
False
Start
Condition
Execute the
following set of rules
End
True
False
Break and Continue are used to skip or break the loop if upon request
for (i = 0; i < 10; i++) {
if (i === 5)
break;
text += "i = " + i;
}
for (i = 0; i < 10; i++) {
if (i === 5)
continue;
text += "i = " + i;
}
26
JS SYNTAX,
LOOPS STATEMENT [3]
© 2021 arche1.co.jp | jaist.ac.jp
All rights reserved.
P A G E 27
JavaScript
Language Syntax: Functions
A JavaScript function is a block of code designed to perform a particular task.
function printMessage() {
console.log("JS is a great language");
}
printMessage();
function times(num1, num2) {
console.log("The first number time the second number = " + num1 * num2);
}
time(5, 4);
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
var Cel = toCelsius(95);
28
JS SYNTAX,
FUNCTIONS
© 2021 arche1.co.jp | jaist.ac.jp
All rights reserved.
P A G E 29
HOMEWORK
Let's Exercise What We've Learned
Write a JS code for solving a problem of your choice that contains all the statements you’ve learned today
30
DEADLINE 6/6,
HOMEWORK
Algorithms, Computer Graphics, and Mathematics
for Game Developers and Computer Scientists
© 2021 arche1.co.jp | jaist.ac.jp
All rights reserved.
THANKS FOR YOUR
ATTENTION

More Related Content

PPTX
Javascript functions
Alaref Abushaala
 
PPTX
Java script
Prarthan P
 
PDF
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
Edureka!
 
PPT
JavaScript Data Types
Charles Russell
 
PPTX
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
PPT
C++ classes tutorials
Mayank Jain
 
PDF
Object Oriented Programming using C++ Part I
Ajit Nayak
 
PPSX
DIWE - Programming with JavaScript
Rasan Samarasinghe
 
Javascript functions
Alaref Abushaala
 
Java script
Prarthan P
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
Edureka!
 
JavaScript Data Types
Charles Russell
 
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
C++ classes tutorials
Mayank Jain
 
Object Oriented Programming using C++ Part I
Ajit Nayak
 
DIWE - Programming with JavaScript
Rasan Samarasinghe
 

What's hot (20)

PPTX
Kotlin
YeldosTanikin
 
PDF
Constructors destructors
Pranali Chaudhari
 
PDF
Java Persistence API
Ilio Catallo
 
PDF
Introduction to Smalltalk
kim.mens
 
PDF
Textual Modeling Framework Xtext
Sebastian Zarnekow
 
PDF
Smalltalk, the dynamic language
mohamedsamyali
 
PPTX
Objective c slide I
Diksha Bhargava
 
KEY
Parte II Objective C
Paolo Quadrani
 
PDF
Maths&programming forartists wip
kedar nath
 
PPTX
Domain-Specific Languages
Javier Canovas
 
PPTX
Aspdot
Nishad Nizarudeen
 
PDF
3. Java Script
Jalpesh Vasa
 
PDF
Mel for beginners
kedar nath
 
PDF
Extending the Xbase Typesystem
Sebastian Zarnekow
 
PPTX
javascript
Kaya Ota
 
PPTX
Oops presentation
sushamaGavarskar1
 
PPT
Javascript
guest03a6e6
 
PDF
Python for katana
kedar nath
 
PDF
01 objective-c session 1
Amr Elghadban (AmrAngry)
 
PPT
Classes1
phanleson
 
Constructors destructors
Pranali Chaudhari
 
Java Persistence API
Ilio Catallo
 
Introduction to Smalltalk
kim.mens
 
Textual Modeling Framework Xtext
Sebastian Zarnekow
 
Smalltalk, the dynamic language
mohamedsamyali
 
Objective c slide I
Diksha Bhargava
 
Parte II Objective C
Paolo Quadrani
 
Maths&programming forartists wip
kedar nath
 
Domain-Specific Languages
Javier Canovas
 
3. Java Script
Jalpesh Vasa
 
Mel for beginners
kedar nath
 
Extending the Xbase Typesystem
Sebastian Zarnekow
 
javascript
Kaya Ota
 
Oops presentation
sushamaGavarskar1
 
Javascript
guest03a6e6
 
Python for katana
kedar nath
 
01 objective-c session 1
Amr Elghadban (AmrAngry)
 
Classes1
phanleson
 
Ad

Similar to Class[2][29th may] [javascript] (20)

PPTX
Clojure And Swing
Skills Matter
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Terence Barr - jdk7+8 - 24mai2011
Agora Group
 
PDF
Java se-7-evolves-toulouse-jug-2001-09-14
Baptiste Mathus
 
PDF
mloc.js 2014 - JavaScript and the browser as a platform for game development
David Galeano
 
PDF
Basics of JavaScript
Bala Narayanan
 
PDF
Oh the compilers you'll build
Mark Stoodley
 
PPS
CS101- Introduction to Computing- Lecture 35
Bilal Ahmed
 
PPTX
04-JS.pptx
RazanMazen4
 
PPTX
04-JS.pptx
RazanMazen4
 
PPTX
04-JS.pptx
RazanMazen4
 
KEY
Exciting JavaScript - Part II
Eugene Lazutkin
 
PPTX
Class[3][5th jun] [three js]
Saajid Akram
 
PDF
22 Jop Oct 08
Ganesh Samarthyam
 
PPTX
Chapter1.pptx
WondimuBantihun1
 
PDF
Practical Groovy DSL
Guillaume Laforge
 
PDF
Scala + WattzOn, sitting in a tree....
Raffi Krikorian
 
PDF
JCConf 2020 - New Java Features Released in 2020
Joseph Kuo
 
DOCX
Lab Practices and Works Documentation / Report on Computer Graphics
Rup Chowdhury
 
PPT
Project seminar ppt_steelcasting
Rudra Narayan Paul
 
Clojure And Swing
Skills Matter
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Terence Barr - jdk7+8 - 24mai2011
Agora Group
 
Java se-7-evolves-toulouse-jug-2001-09-14
Baptiste Mathus
 
mloc.js 2014 - JavaScript and the browser as a platform for game development
David Galeano
 
Basics of JavaScript
Bala Narayanan
 
Oh the compilers you'll build
Mark Stoodley
 
CS101- Introduction to Computing- Lecture 35
Bilal Ahmed
 
04-JS.pptx
RazanMazen4
 
04-JS.pptx
RazanMazen4
 
04-JS.pptx
RazanMazen4
 
Exciting JavaScript - Part II
Eugene Lazutkin
 
Class[3][5th jun] [three js]
Saajid Akram
 
22 Jop Oct 08
Ganesh Samarthyam
 
Chapter1.pptx
WondimuBantihun1
 
Practical Groovy DSL
Guillaume Laforge
 
Scala + WattzOn, sitting in a tree....
Raffi Krikorian
 
JCConf 2020 - New Java Features Released in 2020
Joseph Kuo
 
Lab Practices and Works Documentation / Report on Computer Graphics
Rup Chowdhury
 
Project seminar ppt_steelcasting
Rudra Narayan Paul
 
Ad

More from Saajid Akram (7)

PPTX
Workshop[22nd august][assignments]
Saajid Akram
 
PPTX
Class[6][5th aug] [three js-loaders]
Saajid Akram
 
PPTX
Class[5][9th jul] [three js-meshes_geometries_and_primitives]
Saajid Akram
 
PPTX
Class[4][19th jun] [three js-camera&amp;light]
Saajid Akram
 
PPTX
Class[1][23ed may] [algorithms]
Saajid Akram
 
PPTX
Workshop[3ed Apr]-[Git]
Saajid Akram
 
PPTX
Workshop[1st apr]-[introduction]
Saajid Akram
 
Workshop[22nd august][assignments]
Saajid Akram
 
Class[6][5th aug] [three js-loaders]
Saajid Akram
 
Class[5][9th jul] [three js-meshes_geometries_and_primitives]
Saajid Akram
 
Class[4][19th jun] [three js-camera&amp;light]
Saajid Akram
 
Class[1][23ed may] [algorithms]
Saajid Akram
 
Workshop[3ed Apr]-[Git]
Saajid Akram
 
Workshop[1st apr]-[introduction]
Saajid Akram
 

Recently uploaded (20)

PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
Wings of Fire Book by Dr. A.P.J Abdul Kalam Full PDF
hetalvaishnav93
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Wings of Fire Book by Dr. A.P.J Abdul Kalam Full PDF
hetalvaishnav93
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 

Class[2][29th may] [javascript]

  • 1. ALGORITHMS, COMPUTER GRAPHICS, AND MATHEMATICS FOR GAME DEVELOPERS & COMPUTER SCIENTISTS Class[2]: Introduction to JavaScript [Part 1] PREPARED AND PRESENTED BY Dr.Saajid Abuluaih, PhD 30th of May, 2021
  • 2. Algorithms, Computer Graphics, and Mathematics for Game Developers and Computer Scientists © 2021 arche1.co.jp | jaist.ac.jp All rights reserved. 2 Agenda One-Bite Wisdom JS Syntax: Variables & Operators JS Syntax: Conditional Statements 𝑖 JS Syntax: Loops Introduction to JS: Brief JS Syntax: Functions Today’s Algorithm 𝑔 𝑛 “The future is not just unwritten - it is unsearched” -Bruce Sterling
  • 3. © 2021 arche1.co.jp | jaist.ac.jp All rights reserved. P A G E 3 One-Bite Wisdom RHIND PAPYRUS
  • 4. 4 ANCIENT EGYPTIAN MATH RIDDLE, RHIND MATHEMATICAL PAPYRUS References: Math Puzzles’ Oldest Ancestors Took Form on Egyptian Papyrus Episode Transcript – Episode 17 - Rhind Mathematical Papyrus Rhind papyrus In seven houses there are seven cats. Each cat catches seven mice. Each mouse would have eaten seven ears of corn and each ear of corn, if sown, would have produced seven gallons of grain. How many things are mentioned in total? (made around 3,500 years ago)
  • 5. 5 ANCIENT EGYPTIAN MATH RIDDLE, RHIND MATHEMATICAL PAPYRUS References: Math Puzzles’ Oldest Ancestors Took Form on Egyptian Papyrus Episode Transcript – Episode 17 - Rhind Mathematical Papyrus Rhind papyrus In seven houses there are seven cats. Each cat catches seven mice. Each mouse would have eaten seven ears of corn and each ear of corn, if sown, would have produced seven gallons of grain. How many things are mentioned in total? (made around 3,500 years ago) The answer is as easy as: 7 + 72 + 73 + 74 + 75
  • 6. Algorithms, Computer Graphics, and Mathematics for Game Developers and Computer Scientists © 2021 arche1.co.jp | jaist.ac.jp All rights reserved. WHAT THAT HAS TO DO WITH OUR CLASS FOR TODAY? NOTHING it has nothing to do with today’s class
  • 7. © 2021 arche1.co.jp | jaist.ac.jp All rights reserved. P A G E 7 Simple Algorithms Let’s Brush our Coding Skills
  • 8. Given a string, replace each its character by the next one in the English alphabet (z would be replaced by a). Example: Example: “o`kdrshmd”, the output should be “palestine” 8 A SIMPLE ALGORITHM, Alphabet Shifter
  • 9. Given a string, replace each its character by the next one in the English alphabet (z would be replaced by a). Example: “o`kdrshmd”, the output should be “palestine” • Method [1] (Stupid): 9 A SIMPLE ALGORITHM, Alphabet Shifter function Alphabet_Shift(str) { var dictionary = { 'a' : 'b', 'b' : 'c', 'c' : 'd', 'd' : 'e', 'e' : 'f', 'f' : 'g', 'g' : 'h', 'h' : 'i', 'i' : 'j', 'j' : 'k', 'k' : 'l', 'l' : 'm', 'm' : 'n', 'n' : 'o', 'o' : 'p', 'p' : 'q', 'q' : 'r', 'r' : 's', 's' : 't', 't' : 'u', 'u' : 'v', 'v' : 'w', 'w' : 'x', 'x' : 'y', 'y' : 'z', 'z' : 'a’}; var temp = str.split(''); for(var i=0; i<temp.length; i++){ temp[i] = dictionary[temp[i]] } return temp.join(""); }
  • 10. Given a string, replace each its character by the next one in the English alphabet (z would be replaced by a). Example: “o`kdrshmd”, the output should be “palestine” • Method [2] (smarter solution): 10 A SIMPLE ALGORITHM, Alphabet Shifter function alphabet_char_Shift(str) { var all_chars = str.split(''); for(var i = 0; i < all_chars.length; i++) { var n = all_chars[i].charCodeAt() - 'a'.charCodeAt(); n = (n + 1) % 26; all_chars[i] = String.fromCharCode(n + 'a'.charCodeAt()); } return all_chars.join(""); } console.log(alphabet_char_Shift("o`kdrshmd")) References: Look at the following solution to see how do they solve the ‘z’ letter.
  • 11. © 2021 arche1.co.jp | jaist.ac.jp All rights reserved. P A G E 11 Introduction What is JavaScript anyway?
  • 12. The early to mid-1990s were a pivotal period in the history of the internet. Browser wars were raging between major players like Netscape and Microsoft, with Netscape's Navigator and Microsoft's Internet Explorer going head-to-head. Due to the rapid growth of JavaScript, it became evident in 1997 that the language would need to be properly maintained and managed. As a result, Netscape delegated the task of developing a language definition to the European Computer Manufacturers Association (ECMA), an organization dedicated to computer standardization. 12 INTRODUCTION, BRIEF HISTORY References: The History of JavaScript: Everything You Need to Know Netscape Navigator 2 - JavaScript was developed by NetScape to provide functionality to their internet browser in 1995 - Netscape handed the job of creating a language specification to the European Computer Manufacturers Association (ECMA)
  • 13. JavaScript is a scripting language designed for building interactive functionalities to websites. It is one of the three most common languages for web development. Unlike HTML and CSS, which offer a website's structure and appearance, JavaScript allows you to programs functionality and handle event behaviors to webpages, allowing visitors to interact with page’s contents. JavaScript is designed to operate on client-side. That means, the browser receives a copy of the source code and runs it on the client machine within the browser environment. However, recently the introduction of Node.js, JavaScript can now execute code on servers as well. 13 INTRODUCTION, WHAT THIS COURSE IS ALL ABOUT - HTML: is a markup language for managing the contents - CSS: cascading style sheet for styling webpages contents - JavaScript: programing language for webpabes - Most likely to be used as a Client-Side Programming language - JavaScript is an interpreter not a compiler - JavaScript is a case-sensitive language - JavaScript is a whitespace insensitive - JavaScript has nothing to do with Java
  • 14. © 2021 arche1.co.jp | jaist.ac.jp All rights reserved. P A G E 14 JavaScript Language Syntax: Variables & Operators
  • 15. The structure of delivering classes: • Single line comment // • Multi-lines comment /* */ 15 JS SYNTAX, COMMENTS
  • 16. To store values, you can use variables. There are three primitive data types, and they are: Numbers, Strings, and Booleans. • Declare variables using var keyword, or the key word let (Homework: what is the differences between them both?) • You can use the const keyword to define variable that cannot be reassigned var x = 5; var y = 6; var z = x + y; const pi = 3.14; let personFirstName = "Hiroyuki"; let personLastName = 'Iida’; let personFullName = personFirstName + " " + personLastName; var bool1 = true; var bool2 = 11 < 10; var arr = [true, 'true', 1]; 16 JS SYNTAX, VARIABLES DECLARATION & TYPES [1]
  • 17. Objects is one of the most common variable types used in the language. var car = {type:"Toyota", model:"500", color:"white"}; The Key:Value pairs in JavaScript objects are called properties You can access object’s properties using the following two methods: • car.type • car["type"] An object can have functions as well: var car = { type:"Toyota", model:"500", color:"white", fullInfo:function() { return this.type + " " + this.model + " " + this.color; } }; 17 JS SYNTAX, VARIABLES DECLARATION & TYPES [2]
  • 18. Arithmetic operators are used to perform arithmetic on values of type numbers. 18 JS SYNTAX, OPERATORS [PART 1] Operator Description + Addition - Subtraction * Multiplication ** Exponentiation / Division % Modulus (Division Remainder) ++ Increment -- Decrement Operator Example Same As = x = y x = y += x += y x = x + y -= x -= y x = x - y *= x *= y x = x * y /= x /= y x = x / y %= x %= y x = x % y **= x **= y x = x ** y Can you tell the difference of the following statements? var x = 5; x++; var y = 6; ++y;
  • 19. Comparison and Logical operators are used to test a statement to check whether it is true or false. 19 JS SYNTAX, OPERATORS [PART 2] Operator Description == equal to === equal value and equal type != not equal !== not equal value or not equal type > greater than < less than >= greater than or equal to <= less than or equal to ? ternary operator Operator Description && logical and || logical or ! logical not Can you tell the difference of the following statements? var voltage = (volt == 110) ? "low voltage" : "high voltage";
  • 20. © 2021 arche1.co.jp | jaist.ac.jp All rights reserved. P A G E 20 JavaScript Language Syntax: Conditional Statement
  • 21. Conditional statement is a set of rules performed if a certain set of constraints is met (IF a set of constraints is true THEN perform the following rules). if (Condition) { statements; } if (Condition) { statements; } else { statements; } 21 JS SYNTAX, CONDITIONAL STATEMENT [1] Start Condition Execute the following set of rules End Start Condition Execute the following set of rules End Execute another set of rules True False False True
  • 22. Switch statement is used to perform a set of actions based on different sets of conditions var day = ""; switch (dayNum) { case 0: day = "Sunday"; break; case 1: day = "Monday"; break; case 2: day = "Tuesday"; break; case 3: day = "Wednesday"; break; default: day = " undefined"; } 22 JS SYNTAX, CONDITIONAL STATEMENT [2] Start Condition Execute the following set of rules End False True Condition Execute the following set of rules False True Condition Execute the following set of rules False True Execute the default set of rules
  • 23. © 2021 arche1.co.jp | jaist.ac.jp All rights reserved. P A G E 23 JavaScript Language Syntax: Loop Statement
  • 24. Loops used to repeat a specific block of code until some condition is met. for (i = 0; i < length; i++) { statements; } You can move more than one step at a time. There are the following loops that works with arrays and objects: var obj = {prop1:"Hiroyuki", prop2:"Iida"}; var fullName = ""; var x; for (x in obj) { fullName += obj[x] + " "; } let arr = ["elm1", "elm2", "elm3"]; let text = ""; for (let x of cars) { text += x + " ";} 24 JS SYNTAX, LOOPS STATEMENT [1] Start Condition Execute the following set of rules End True False
  • 25. Loops used to repeat a specific block of code until some condition is met. while (i < 10) { text += "i = " + i; i++; } do { text += "The number is " + i; i++; } while (i < 10); 25 JS SYNTAX, LOOPS STATEMENT [2] Start Condition Execute the following set of rules End True False Start Condition Execute the following set of rules End True False
  • 26. Break and Continue are used to skip or break the loop if upon request for (i = 0; i < 10; i++) { if (i === 5) break; text += "i = " + i; } for (i = 0; i < 10; i++) { if (i === 5) continue; text += "i = " + i; } 26 JS SYNTAX, LOOPS STATEMENT [3]
  • 27. © 2021 arche1.co.jp | jaist.ac.jp All rights reserved. P A G E 27 JavaScript Language Syntax: Functions
  • 28. A JavaScript function is a block of code designed to perform a particular task. function printMessage() { console.log("JS is a great language"); } printMessage(); function times(num1, num2) { console.log("The first number time the second number = " + num1 * num2); } time(5, 4); function toCelsius(fahrenheit) { return (5/9) * (fahrenheit-32); } var Cel = toCelsius(95); 28 JS SYNTAX, FUNCTIONS
  • 29. © 2021 arche1.co.jp | jaist.ac.jp All rights reserved. P A G E 29 HOMEWORK Let's Exercise What We've Learned
  • 30. Write a JS code for solving a problem of your choice that contains all the statements you’ve learned today 30 DEADLINE 6/6, HOMEWORK
  • 31. Algorithms, Computer Graphics, and Mathematics for Game Developers and Computer Scientists © 2021 arche1.co.jp | jaist.ac.jp All rights reserved. THANKS FOR YOUR ATTENTION