SlideShare a Scribd company logo
1 of 31
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

What's hot (20)

Kotlin
KotlinKotlin
Kotlin
 
Constructors destructors
Constructors destructorsConstructors destructors
Constructors destructors
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalk
 
Textual Modeling Framework Xtext
Textual Modeling Framework XtextTextual Modeling Framework Xtext
Textual Modeling Framework Xtext
 
Smalltalk, the dynamic language
Smalltalk, the dynamic languageSmalltalk, the dynamic language
Smalltalk, the dynamic language
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
Parte II Objective C
Parte II   Objective CParte II   Objective C
Parte II Objective C
 
Maths&programming forartists wip
Maths&programming forartists wipMaths&programming forartists wip
Maths&programming forartists wip
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific Languages
 
Aspdot
AspdotAspdot
Aspdot
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
Mel for beginners
Mel for beginnersMel for beginners
Mel for beginners
 
Extending the Xbase Typesystem
Extending the Xbase TypesystemExtending the Xbase Typesystem
Extending the Xbase Typesystem
 
javascript
javascript javascript
javascript
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
Javascript
JavascriptJavascript
Javascript
 
Python for katana
Python for katanaPython for katana
Python for katana
 
01 objective-c session 1
01  objective-c session 101  objective-c session 1
01 objective-c session 1
 
Classes1
Classes1Classes1
Classes1
 

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

Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Agora Group
 
Java se-7-evolves-toulouse-jug-2001-09-14
Java se-7-evolves-toulouse-jug-2001-09-14Java se-7-evolves-toulouse-jug-2001-09-14
Java se-7-evolves-toulouse-jug-2001-09-14Baptiste Mathus
 
mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentDavid Galeano
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll buildMark Stoodley
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35Bilal Ahmed
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part IIEugene Lazutkin
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11Jadavsejal
 
Class[3][5th jun] [three js]
Class[3][5th jun] [three js]Class[3][5th jun] [three js]
Class[3][5th jun] [three js]Saajid Akram
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Raffi Krikorian
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020Joseph Kuo
 
Project seminar ppt_steelcasting
Project seminar ppt_steelcastingProject seminar ppt_steelcasting
Project seminar ppt_steelcastingRudra Narayan Paul
 

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

Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011
 
Java se-7-evolves-toulouse-jug-2001-09-14
Java se-7-evolves-toulouse-jug-2001-09-14Java se-7-evolves-toulouse-jug-2001-09-14
Java se-7-evolves-toulouse-jug-2001-09-14
 
mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game development
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35
 
04-JS.pptx
04-JS.pptx04-JS.pptx
04-JS.pptx
 
04-JS.pptx
04-JS.pptx04-JS.pptx
04-JS.pptx
 
04-JS.pptx
04-JS.pptx04-JS.pptx
04-JS.pptx
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part II
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11
 
Class[3][5th jun] [three js]
Class[3][5th jun] [three js]Class[3][5th jun] [three js]
Class[3][5th jun] [three js]
 
An Intoduction to R
An Intoduction to RAn Intoduction to R
An Intoduction to R
 
22 Jop Oct 08
22 Jop Oct 0822 Jop Oct 08
22 Jop Oct 08
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Practical Groovy DSL
Practical Groovy DSLPractical Groovy DSL
Practical Groovy DSL
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
 
Project seminar ppt_steelcasting
Project seminar ppt_steelcastingProject seminar ppt_steelcasting
Project seminar ppt_steelcasting
 

More from Saajid Akram

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

More from Saajid Akram (7)

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

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 

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