SlideShare a Scribd company logo
2
Most read
4
Most read
6
Most read
JAVASCRIPT CHEATSHEET IN GEOGEBRA
JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA
Single line comments- //
Multi-line comments- /* comment here */
var- The most common variable. Can be reassigned but only
accessed within a function. Variables defined with var move to the
top when code is executed.
const- Cannot be reassigned and not accessible before they appear
within the code.
Numbers- var num = 17;
Variables- var x;
Text (strings)- var a = "algebra";
Operations- var b = 1 + 4+ 9;
True or false statements- var c = true;
Notation Scientific-
var num1=1e10, num2=4e-9;
Constant numbers- const PI = 3.1416;
Basic Operators
+ Addition, - Subtraction, * Multiplication, / Division
(...) Grouping operator, % Modulus (remainder)
Increment/Decrement Numbers
i++ Postfix Increment numbers
i-- Postfix Decrement numbers
++i Prefix Increment numbers
--i Prefix Decrement numbers
var var1 = 5, var2 = 5;
alert(var1++); //5
alert(++var2); //6.0
alert(var1--); //6.0
alert(--var2); //5.0
Assigment and Operators
a += b //a = a + b Add then assign
a -= b //a = a – b Subtract then assign
a *= b //a = a * b Multiply then assign
a /= b //a = a / b Divide then assign
Comparison Operators
== Equal to, != Not equal, > Greater than, < Less than,
>= Greater than or equal to, <= Less than or equal to
Ternary Operator ?- (expression)? ifTrue: ifFalse
function getTF(isMember) {
return (isMember ? 'True' : 'False');
}
alert(getTF(true)+"n"+getTF(false)+"n"+getTF(1));
Logical Operators
&& Logical and-
alert((1 > 0) && (4 > 0));
|| Logical or-
alert((1 > 3) || (4 > 3));
! Logical not-
alert(!(1 == 1));
Bitwise Operators
& AND statement, | OR statement, ~ NOT, ^ XOR,
<< Left shift, >> Right shift, >>> Zero fill right shift
alert("5&1="+(5&1) +
"5|1="+(5|1) +
"~5="+(~5) +
"5<<1="+(5<<1) +
"5^1="+(5^1) +
"5>>1="+(5>>1) +
"5>>>1="+5>>>1);
JAVASCRIPT CHEATSHEET IN GEOGEBRA
JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA
Functions
function namefunction(parameter1, parameter2, parameter3)
{ // what the function does }
Outputting Data
alert()- Output data in an alert box in the browser window.
alert("Welcome to Geogebra");
prompt()- Creates an dialogue for user input.
var value=Number(prompt("Enter value: ",1));
Global Functions
eval()- Evaluates JavaScript code represented as a string.
alert(eval("x = 2+3"));
var x = 10;
var y = 20;
var a = eval("x * y") ;
var b = eval("2 + 2");
var c = eval("x + 17");
var res = a + b + c;
alert(a+"+"+b+"+"+c+"="+res)
isFinite()- Determines whether a passed value is a finite number.
isNaN()- Determines whether a value is NaN or not.
Number()- Returns a number converted from its argument.
parseFloat()- Parses an argument and returns a floating-point
number.
parseInt()- Parses its argument and returns an integer.
JAVASCRIPT LOOPS
for- The most common way to create a loop in JavaScript.
for (before loop; condition for loop; execute after loop) {
// what to do during the loop }
var str="";
for (var i = 0; i < 10; i++) {
str=str+i + ": " + i*3 + "n";
}
alert(str);
var sum = 0;
for (var i = 0; i < a.length; i++) {
sum + = a[i];
} // parsing an array
while- Sets up conditions under which a loop executes.
var i = 1; // initialize
var str=""; // initialize
while (i < 100) { // enters the cycle if statement is true
i *= 2; // increment to avoid infinite loop
str=str+i + ", "; // output
}
alert(str);
do while- Similar to the while loop, however, it executes at least
once and performs a check at the end to see if the condition is met
to execute again.
var i = 1; // initialize
var str=""; // initialize
do { // enters cycle at least once
i *= 2; // increment to avoid infinite loop
str=str+(i + ", "); // output
} while (i < 100) // repeats cycle if statement is true at the end
alert(str);
JAVASCRIPT CHEATSHEET IN GEOGEBRA
JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA
break- Use to stop and exit the cycle at certain conditions.
var i = 1; // initialize
var str=""; // initialize
for (var i = 0; i < 10; i++) {
if (i == 5) { break; } // stops and exits the cycle
str=str+(i + ", "); // last output number is 4
}
alert(str);
continue- Skip parts of the cycle if certain conditions are met.
var i = 1; // initialize
var str=""; // initialize
for (var i = 0; i < 10; i++) {
if (i == 5) { continue; } // skips the rest of the cycle
str=str+(i + ", "); // skips 5
}
alert(str);
IF - ELSE STATEMENTS
if (condition) {
// what to do if condition is met
} else {
// what to do if condition is not met
}
if(n%2){
alert("Number is odd.");
}else{
alert("Number is even.");
}
IF - ELSE NESTED STATEMENTS
var number=Number(prompt("Enter number",0));
if (number > 0) {
alert("Positive");
}else if (number < 0) {
alert("Negative");
}else{
alert("Zero");
}
SWITCH STATEMENTS
var n=333;
switch (n%4) {
case 0:
result = "1"; break;
case 1:
result = "i"; break;
case 2:
result = "-1"; break;
case 3:
result = "-i"; break;
default:
result="Null";
}
alert("i^"+n+" = "+result);
Objects Definition and Properties
Initialize Objects- var obj3D = {name:"Sphere", radius:2};
alert("Object="+obj3D.name+"nradius="+obj3D.radius);
JAVASCRIPT CHEATSHEET IN GEOGEBRA
JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA
Initialize Objects-
var obj2D = { name:"Triangle", area:20, perimeter:24,
type:"rectangle"};
alert("Object=" + obj2D.name+" "+ obj2D.type + "nArea=" +
obj2D.area);
Initialize Objects-
var polygon = new Object();
polygon.type = "quadrilateral";
polygon.property = "trapezoidal";
polygon.area = 50;
polygon.perimeter = 60;
alert(polygon.type+"n"+
polygon.property +"n"+
polygon.area+"n"+
polygon.perimeter);
Initialize Functions in Objects-
var obj = {name: "Straight",
type: "Angle",
getName: function() { alert (this.name);}
};
obj.getName();
Initialize String Array- "
var course = ["Geometry","Trigonometry","Calculus"];
var course= new Array("Geometry", "Trigonometry", "Calculus");
var list1 = [2,3,5,8];
var list1 = new Array(2,3,5,8);
Declare Array Dynamic
var arr=new Array();
Array Methods
arr.length- Returns the number of elements in an array.
arr.concat()- Join several arrays into one.
arr.indexOf()- Returns the primitive value of the specified object.
arr.join()- Combine elements of an array into a single string and
return the string.
arr.lastIndexOf()- Gives the last position at which a given element
appears in an array.
arr.pop()- Removes the last element of an array.
arr.push()- Add a new element at the end.
arr.reverse()- Sort elements in descending order.
arr.shift()- Remove the first element of an array.
arr.slice()- Pulls a copy of a portion of an array into a new array.
arr.sort()- Sorts elements alphabetically.
arr.splice()- Adds elements in a specified way and position.
arr.toString()- Converts elements to strings.
arr.unshift()- Adds a new element to the beginning.
arr.valueOf()- Returns the first position at which a given element
appears in an array.
Initialization of a 2d Array Static
var c[2][3] = {{1, 3, 0}, {-1, 5, 9}};
Set Value Element in 2D Array- c[1][2]=4;
Get Value Element in 2D Array- num=c[2][1];
STRINGS
var CEO="Markus Hohenwarter";
var str= "javascript";
alert(str.length);
length- the length of the string
Escape Characters
' - Single quote, " - Double quote,  - Backslash
r - Carriage return, 0 - NUL character
n - A new line characte
JAVASCRIPT CHEATSHEET IN GEOGEBRA
JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA
String Concatenation
var nside = 3;
alert('Triangles have ' + nside + ' sides.');
String Methods
charAt()- Returns a character at a specified position inside a string.
charCodeAt()- Gives you the unicode of character at that position.
concat()- Concatenates (joins) two or more strings into one.
fromCharCode()- Returns a string created from the specified.
sequence of UTF-16 code units.
indexOf()- Provides the position of the first occurrence of a
specified text within a string.
lastIndexOf()- Same as indexOf() but with the last occurrence,
searching backwards.
match()- Retrieves the matches of a string against a search pattern.
replace()- Find and replace specified text in a string.
search()- Executes a search for a matching text and returns its
position.
slice()- Extracts a section of a string and returns it as a new string.
split()- Splits a string object into an array of strings at a specified
position.
substr()- Similar to slice() but extracts a substring depended on a
specified number of characters.
substring()- Also similar to slice() but cannot accept negative
indices.
toLowerCase()- Convert strings to lower case.
toUpperCase()- Convert strings to upper case.
valueOf()- Returns the primitive value of a string object.
NUMBERS AND MATH
Number Properties
Math.MAX_VALUE- The maximum numeric value representable in
JavaScript.
Math.MIN_VALUE- Smallest positive numeric value representable
in JavaScript.
Math.NaN- The "Not-a-Number" value.
Math.NEGATIVE_INFINITY- The negative Infinity value.
Math.POSITIVE_INFINITY- Positive Infinity value Number Methods.
alert("MAX_VALUE="+Math.MAX_VALUE+
"nMIN_VALUE="+Math.MIN_VALUE+
"nNaN="+Math.NaN+
"nNEGATIVE_INFINITY="+Math.NEGATIVE_INFINITY+
"nPOSITIVE_INFINITY="+Math.POSITIVE_INFINITY);
Number Functions
var num=Number("2");
num.toExponential()- Returns a string with a rounded number
written as exponential notation.
num.toFixed()- Returns the string of a number with a specified
number of decimals.
num.toPrecision()- String of a number written with a specified
length.
num.toString()- Returns a number as a string.
num.valueOf()- Returns a number as a number.
Math Properties
Math.E- Euler’s number.
Math.LN2- The natural logarithm of 2.
Math.LN10- Natural logarithm of 10.
Math.LOG2E- Base 2 logarithm of E.
Math.LOG10E- Base 10 logarithm of E.
Math.PI- The number PI.
Math.SQRT1_2- Square root of 1/2.
Math.SQRT2- The square root of 2.
Math Methods and Functions
JAVASCRIPT CHEATSHEET IN GEOGEBRA
JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA
Math.abs(x)- Returns the absolute (positive) value of x
Math.acos(x)- The arccosine of x, in radians
Math.asin(x)- Arcsine of x, in radians
Math.atan(x)- The arctangent of x as a numeric value
Math.atan2(y,x)- Arctangent of the quotient of its arguments
Math.ceil(x)- Value of x rounded up to its nearest integer.
Math.cos(x)- The cosine of x (x is in radians).
Math.exp(x)- Value of exponential.
Math.floor(x)- The value of x rounded down to its nearest integer.
Math.log(x)- The natural logarithm (base E) of x.
Math.max(x,y,z,...,n)- Returns the number with the highest value.
alert(Math.max(2,3,4));
Math.min(x,y,z, ...,n)- Same for the number with the lowest value.
alert(Math.min(-2,-3,-4));
Math.pow(x,y)- X to the power of y.
Math.random()- Returns a random number between 0 and 1.
Math.round(x)- The value of x rounded to its nearest integer.
Math.sin(x)- The sine of x (x is in radians).
Math.sqrt(x)- Square root of x.
Math.tan(x)- The tangent of an angle.
Errors
try- Lets you define a block of code to test for errors.
catch- Set up a block of code to execute in case of an error.
throw- Create custom error messages instead of the standard
JavaScript errors.
finally- Lets you execute code, after try and catch, regardless of the
result.
var x =Number(prompt("Enter x"));
try{
if(x == "") throw "empty"; //error cases
if(isNaN(x)) throw "not a number";
x = Number(x);
if(x > 10) throw "too high";
}catch(err) { //if there's an error
alert("Input is " + err); //output error
}finally{
alert("Done"); //executed regardless of the try / catch result
}
var ver=parseInt(ggbApplet.getVersion());
try{
if(ver== 5.0){
var A=prompt("Enter Matrix:","0,1,0,1,4; -5,4,2,6,15; -3,2,1,3,8; 2,-
1,0,-2,-5; -1,2,0,0,0");
}else{
var A = "" + ggbApplet.getValueString("Matrix");
}}catch(err){
alert("Error");
}finally{
alert("Version: "+ver);
}
Setting Dates
var d = new Date();
Date()- Creates a new date object with the current date and time
Date(2017, 5, 21, 3, 23, 10, 0)- Create a custom date object. The
numbers represent year, month, day, hour, minutes, seconds,
milliseconds. You can omit anything you want except for year and
month.
Date("2017-06-23")- Date declaration as a string Pulling Date and
Time Values.
d.getDate()- Get the day of the month as a number (1-31)
JAVASCRIPT CHEATSHEET IN GEOGEBRA
JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA
d.getDay()- The weekday as a number (0-6) Sunday-0, Monday-1,
Tuesday-2, Wednesday-3, Thursday, Friday-5, and Saturday-6.
d.getFullYear()- Year as a four-digit number (yyyy)
d.getHours()- Get the hour (0-23)
d.getMilliseconds()- The millisecond (0-999)
d.getMinutes()- Get the minute (0-59)
d.getMonth()- Month as a number (0-11)
d.getSeconds()- Get the second (0-59)
d.getTime()- Get the milliseconds since January 1, 1970
d.getUTCDate()- The day of the month in the specified date
according to universal time.
Date.now()- Returns the number of milliseconds elapsed since
January 1, 1970, 00:00:00 UTC.
Date.parse()- Parses a string representation of a date, and returns
the number of milliseconds since January 1, 1970.
const unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT');
const javaScriptRelease = Date.parse('04 Dec 1995 00:12:00 GMT');
alert("unixTimeZero="+ unixTimeZero+
"nJavaScriptRelease="+javaScriptRelease);
d.setDate()- Set the day as a number (1-31)
d.setFullYear()- Sets the year (optionally month and day)
d.setHours()- Set the hour (0-23)
d.setMilliseconds()- Set milliseconds (0-999)
d.setMinutes()- Sets the minutes (0-59)
d.setMonth()- Set the month (0-11)
d.setSeconds()- Sets the seconds (0-59)
d.setTime()- Set the time (milliseconds since January 1, 1970)
d.setUTCDate()- Sets the day of the month for a specified date
according to universal time.
var d = new Date();
d.setFullYear(2008, 05, 15);
alert(d.getFullYear()+"-"+d.getMonth()+"-"+d.getDate());
ggbAppletMethods
var n=ggbApplet.getValue("n");
ggbApplet.setValue("a",1);
ggbApplet.evalCommand("l1={}");
ggbApplet.setListValue("l1", i, Math.random() * (vmax - vmin) +
vmin);
Notepad++ is a text and source code editor to JavaScript.
https://notepad-plus-plus.org/downloads/
Use Notepad ++ to create and edit the Geogebra JavaScript code in
Language-> J-> JavaScript and after finishing the code copy the code
in Geogebra JavaScript and compile the code in some Geogebra
object as a button to see if there are errors in the code or if the
code works.
GeoGebra Scripting
https://wiki.geogebra.org/en/Scripting
Reference:GeoGebra Apps API
https://wik.geogebra.org/en/Reference:GeoGebra_Apps_API
JavaScript Tag Search in GeoGebra Web
https://www.geogebra.org/search/tags:JavaScript
Code Snipets of Javascript in Geogebra
https://ww.geogebra.org/m/paxjwmxh
JAVASCRIPT CHEATSHEET IN GEOGEBRA
JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA
Geogebra Scripting JavaScript Notepad++ Source Code Editor JavaScript

More Related Content

PDF
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
PDF
Numerical Methods(Roots of Equations)
Dr. Tushar J Bhatt
 
PDF
Lesson 16: Inverse Trigonometric Functions (slides)
Matthew Leingang
 
PPTX
Group homomorphism
NaliniSPatil
 
PPSX
Methods of solving ODE
kishor pokar
 
PPTX
Python programs - PPT file (Polytechnics)
SHAMJITH KM
 
PDF
Data Structures and Algorithms
Pierre Vigneras
 
PDF
Graphing trigonometric functions
Leo Crisologo
 
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
Numerical Methods(Roots of Equations)
Dr. Tushar J Bhatt
 
Lesson 16: Inverse Trigonometric Functions (slides)
Matthew Leingang
 
Group homomorphism
NaliniSPatil
 
Methods of solving ODE
kishor pokar
 
Python programs - PPT file (Polytechnics)
SHAMJITH KM
 
Data Structures and Algorithms
Pierre Vigneras
 
Graphing trigonometric functions
Leo Crisologo
 

What's hot (20)

PDF
Group Theory and Its Application: Beamer Presentation (PPT)
SIRAJAHMAD36
 
DOC
Gamma beta functions-1
Selvaraj John
 
PPT
Gamma function
Solo Hermelin
 
PDF
Algorithm Design and Analysis - Practical File
KushagraChadha1
 
PPT
1574 multiple integral
Dr Fereidoun Dejahang
 
PPTX
Newton cotes integration method
shashikant pabari
 
PDF
Python Cheat Sheet
GlowTouch
 
PDF
Numerical Methods with Computer Programming
Utsav Patel
 
PPTX
Iterative methods
Ketan Nayak
 
PPT
Weighted graphs
Core Condor
 
PPTX
Euler-Fermat theorem.pptx
Kuparala Vidyasagar
 
PDF
Integration formulas
Krishna Gali
 
PPT
Introduction to Mathematical Probability
Solo Hermelin
 
PPTX
Learn Set Theory
yochevedl
 
PDF
design and analysis of algorithm Lab files
Nitesh Dubey
 
PDF
1586746631GAMMA BETA FUNCTIONS.pdf
Fighting2
 
PPT
First order non-linear partial differential equation & its applications
Jayanshu Gundaniya
 
ODP
Linear cong slide 2
Vi Aspe
 
PDF
2. polynomial interpolation
EasyStudy3
 
PPT
1st order differential equations
Nisarg Amin
 
Group Theory and Its Application: Beamer Presentation (PPT)
SIRAJAHMAD36
 
Gamma beta functions-1
Selvaraj John
 
Gamma function
Solo Hermelin
 
Algorithm Design and Analysis - Practical File
KushagraChadha1
 
1574 multiple integral
Dr Fereidoun Dejahang
 
Newton cotes integration method
shashikant pabari
 
Python Cheat Sheet
GlowTouch
 
Numerical Methods with Computer Programming
Utsav Patel
 
Iterative methods
Ketan Nayak
 
Weighted graphs
Core Condor
 
Euler-Fermat theorem.pptx
Kuparala Vidyasagar
 
Integration formulas
Krishna Gali
 
Introduction to Mathematical Probability
Solo Hermelin
 
Learn Set Theory
yochevedl
 
design and analysis of algorithm Lab files
Nitesh Dubey
 
1586746631GAMMA BETA FUNCTIONS.pdf
Fighting2
 
First order non-linear partial differential equation & its applications
Jayanshu Gundaniya
 
Linear cong slide 2
Vi Aspe
 
2. polynomial interpolation
EasyStudy3
 
1st order differential equations
Nisarg Amin
 
Ad

Similar to GeoGebra JavaScript CheatSheet (20)

PDF
Beauty and the beast - Haskell on JVM
Jarek Ratajski
 
PPTX
Functions
Ankit Dubey
 
PPTX
What is new in Java 8
Sandeep Kr. Singh
 
PDF
Javascript
Vlad Ifrim
 
PPT
03 stacks and_queues_using_arrays
tameemyousaf
 
PPTX
8558537werr.pptx
ssuser8a9aac
 
PDF
Assignment of Advanced data structure and algorithms..pdf
vishuv3466
 
PDF
Assignment of Advanced data structure and algorithms ..pdf
vishuv3466
 
PDF
Assignment of Advanced data structure and algorithm ..pdf
vishuv3466
 
PDF
Meet scala
Wojciech Pituła
 
PPTX
Javascript Basics
msemenistyi
 
PDF
Operator Overloading In Scala
Joey Gibson
 
PDF
TI1220 Lecture 6: First-class Functions
Eelco Visser
 
DOCX
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
andreecapon
 
PDF
JavaScript Array Interview Questions PDF By ScholarHat
Scholarhat
 
DOCX
Spark_Documentation_Template1
Nagavarunkumar Kolla
 
PPT
Php my sql - functions - arrays - tutorial - programmerblog.net
Programmer Blog
 
PDF
Functional programming ii
Prashant Kalkar
 
PDF
C++ Searching & Sorting5. Sort the following list using the select.pdf
Rahul04August
 
Beauty and the beast - Haskell on JVM
Jarek Ratajski
 
Functions
Ankit Dubey
 
What is new in Java 8
Sandeep Kr. Singh
 
Javascript
Vlad Ifrim
 
03 stacks and_queues_using_arrays
tameemyousaf
 
8558537werr.pptx
ssuser8a9aac
 
Assignment of Advanced data structure and algorithms..pdf
vishuv3466
 
Assignment of Advanced data structure and algorithms ..pdf
vishuv3466
 
Assignment of Advanced data structure and algorithm ..pdf
vishuv3466
 
Meet scala
Wojciech Pituła
 
Javascript Basics
msemenistyi
 
Operator Overloading In Scala
Joey Gibson
 
TI1220 Lecture 6: First-class Functions
Eelco Visser
 
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
andreecapon
 
JavaScript Array Interview Questions PDF By ScholarHat
Scholarhat
 
Spark_Documentation_Template1
Nagavarunkumar Kolla
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Programmer Blog
 
Functional programming ii
Prashant Kalkar
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
Rahul04August
 
Ad

More from Jose Perez (20)

PDF
Openboard Regla, Compás, Transportador & Triángulo
Jose Perez
 
PDF
Listado de Ángulos Especiales y Razones Trigonométricas Exactas
Jose Perez
 
PDF
Atajos de Teclado & Shortcuts en OpenBoard
Jose Perez
 
PDF
Open Board Software- La Presentación
Jose Perez
 
PDF
Series Infinitas Convergentes y Divergentes en Geogebra CAS
Jose Perez
 
PDF
Cheatsheet Visual Studio Code
Jose Perez
 
PDF
Cheatsheet de Algebra sobre Propiedades de Signos, Fracciones, Exponentes, Ra...
Jose Perez
 
PDF
Prueba diagnóstica de Algebra sobre Ecuación Lineal
Jose Perez
 
PDF
Glosario de Pronunciación Spanglish
Jose Perez
 
PDF
Resolviendo Ecuaciones Diferenciales Ordinarias Multipartes con Geogebra 6
Jose Perez
 
PDF
Secuencias Recursivas, Sucesiones Recursivas & Progresiones con Geogebra
Jose Perez
 
PDF
Fritzing Software Cheatsheet
Jose Perez
 
PDF
Fritzing Software - Presentación
Jose Perez
 
PDF
Relación entre los parámetros de un cuadrado por lado, diagonal, perímetro y ...
Jose Perez
 
PDF
LaTeX en GeoGebra
Jose Perez
 
PDF
Problemas Verbales de Comisiones Graduadas & Tarifas Graduadas
Jose Perez
 
PDF
Cheatsheet - Divisores del uno al cien
Jose Perez
 
PDF
Dispositivos e instrumentos en ciencias espaciales
Jose Perez
 
PDF
Cheatsheet - Fórmulas de Física para Física General y Física de Ingenieros
Jose Perez
 
PDF
ImageJ and AstroImageJ Software Presentation
Jose Perez
 
Openboard Regla, Compás, Transportador & Triángulo
Jose Perez
 
Listado de Ángulos Especiales y Razones Trigonométricas Exactas
Jose Perez
 
Atajos de Teclado & Shortcuts en OpenBoard
Jose Perez
 
Open Board Software- La Presentación
Jose Perez
 
Series Infinitas Convergentes y Divergentes en Geogebra CAS
Jose Perez
 
Cheatsheet Visual Studio Code
Jose Perez
 
Cheatsheet de Algebra sobre Propiedades de Signos, Fracciones, Exponentes, Ra...
Jose Perez
 
Prueba diagnóstica de Algebra sobre Ecuación Lineal
Jose Perez
 
Glosario de Pronunciación Spanglish
Jose Perez
 
Resolviendo Ecuaciones Diferenciales Ordinarias Multipartes con Geogebra 6
Jose Perez
 
Secuencias Recursivas, Sucesiones Recursivas & Progresiones con Geogebra
Jose Perez
 
Fritzing Software Cheatsheet
Jose Perez
 
Fritzing Software - Presentación
Jose Perez
 
Relación entre los parámetros de un cuadrado por lado, diagonal, perímetro y ...
Jose Perez
 
LaTeX en GeoGebra
Jose Perez
 
Problemas Verbales de Comisiones Graduadas & Tarifas Graduadas
Jose Perez
 
Cheatsheet - Divisores del uno al cien
Jose Perez
 
Dispositivos e instrumentos en ciencias espaciales
Jose Perez
 
Cheatsheet - Fórmulas de Física para Física General y Física de Ingenieros
Jose Perez
 
ImageJ and AstroImageJ Software Presentation
Jose Perez
 

Recently uploaded (20)

PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 

GeoGebra JavaScript CheatSheet

  • 1. JAVASCRIPT CHEATSHEET IN GEOGEBRA JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA Single line comments- // Multi-line comments- /* comment here */ var- The most common variable. Can be reassigned but only accessed within a function. Variables defined with var move to the top when code is executed. const- Cannot be reassigned and not accessible before they appear within the code. Numbers- var num = 17; Variables- var x; Text (strings)- var a = "algebra"; Operations- var b = 1 + 4+ 9; True or false statements- var c = true; Notation Scientific- var num1=1e10, num2=4e-9; Constant numbers- const PI = 3.1416; Basic Operators + Addition, - Subtraction, * Multiplication, / Division (...) Grouping operator, % Modulus (remainder) Increment/Decrement Numbers i++ Postfix Increment numbers i-- Postfix Decrement numbers ++i Prefix Increment numbers --i Prefix Decrement numbers var var1 = 5, var2 = 5; alert(var1++); //5 alert(++var2); //6.0 alert(var1--); //6.0 alert(--var2); //5.0 Assigment and Operators a += b //a = a + b Add then assign a -= b //a = a – b Subtract then assign a *= b //a = a * b Multiply then assign a /= b //a = a / b Divide then assign Comparison Operators == Equal to, != Not equal, > Greater than, < Less than, >= Greater than or equal to, <= Less than or equal to Ternary Operator ?- (expression)? ifTrue: ifFalse function getTF(isMember) { return (isMember ? 'True' : 'False'); } alert(getTF(true)+"n"+getTF(false)+"n"+getTF(1)); Logical Operators && Logical and- alert((1 > 0) && (4 > 0)); || Logical or- alert((1 > 3) || (4 > 3)); ! Logical not- alert(!(1 == 1)); Bitwise Operators & AND statement, | OR statement, ~ NOT, ^ XOR, << Left shift, >> Right shift, >>> Zero fill right shift alert("5&1="+(5&1) + "5|1="+(5|1) + "~5="+(~5) + "5<<1="+(5<<1) + "5^1="+(5^1) + "5>>1="+(5>>1) + "5>>>1="+5>>>1);
  • 2. JAVASCRIPT CHEATSHEET IN GEOGEBRA JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA Functions function namefunction(parameter1, parameter2, parameter3) { // what the function does } Outputting Data alert()- Output data in an alert box in the browser window. alert("Welcome to Geogebra"); prompt()- Creates an dialogue for user input. var value=Number(prompt("Enter value: ",1)); Global Functions eval()- Evaluates JavaScript code represented as a string. alert(eval("x = 2+3")); var x = 10; var y = 20; var a = eval("x * y") ; var b = eval("2 + 2"); var c = eval("x + 17"); var res = a + b + c; alert(a+"+"+b+"+"+c+"="+res) isFinite()- Determines whether a passed value is a finite number. isNaN()- Determines whether a value is NaN or not. Number()- Returns a number converted from its argument. parseFloat()- Parses an argument and returns a floating-point number. parseInt()- Parses its argument and returns an integer. JAVASCRIPT LOOPS for- The most common way to create a loop in JavaScript. for (before loop; condition for loop; execute after loop) { // what to do during the loop } var str=""; for (var i = 0; i < 10; i++) { str=str+i + ": " + i*3 + "n"; } alert(str); var sum = 0; for (var i = 0; i < a.length; i++) { sum + = a[i]; } // parsing an array while- Sets up conditions under which a loop executes. var i = 1; // initialize var str=""; // initialize while (i < 100) { // enters the cycle if statement is true i *= 2; // increment to avoid infinite loop str=str+i + ", "; // output } alert(str); do while- Similar to the while loop, however, it executes at least once and performs a check at the end to see if the condition is met to execute again. var i = 1; // initialize var str=""; // initialize do { // enters cycle at least once i *= 2; // increment to avoid infinite loop str=str+(i + ", "); // output } while (i < 100) // repeats cycle if statement is true at the end alert(str);
  • 3. JAVASCRIPT CHEATSHEET IN GEOGEBRA JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA break- Use to stop and exit the cycle at certain conditions. var i = 1; // initialize var str=""; // initialize for (var i = 0; i < 10; i++) { if (i == 5) { break; } // stops and exits the cycle str=str+(i + ", "); // last output number is 4 } alert(str); continue- Skip parts of the cycle if certain conditions are met. var i = 1; // initialize var str=""; // initialize for (var i = 0; i < 10; i++) { if (i == 5) { continue; } // skips the rest of the cycle str=str+(i + ", "); // skips 5 } alert(str); IF - ELSE STATEMENTS if (condition) { // what to do if condition is met } else { // what to do if condition is not met } if(n%2){ alert("Number is odd."); }else{ alert("Number is even."); } IF - ELSE NESTED STATEMENTS var number=Number(prompt("Enter number",0)); if (number > 0) { alert("Positive"); }else if (number < 0) { alert("Negative"); }else{ alert("Zero"); } SWITCH STATEMENTS var n=333; switch (n%4) { case 0: result = "1"; break; case 1: result = "i"; break; case 2: result = "-1"; break; case 3: result = "-i"; break; default: result="Null"; } alert("i^"+n+" = "+result); Objects Definition and Properties Initialize Objects- var obj3D = {name:"Sphere", radius:2}; alert("Object="+obj3D.name+"nradius="+obj3D.radius);
  • 4. JAVASCRIPT CHEATSHEET IN GEOGEBRA JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA Initialize Objects- var obj2D = { name:"Triangle", area:20, perimeter:24, type:"rectangle"}; alert("Object=" + obj2D.name+" "+ obj2D.type + "nArea=" + obj2D.area); Initialize Objects- var polygon = new Object(); polygon.type = "quadrilateral"; polygon.property = "trapezoidal"; polygon.area = 50; polygon.perimeter = 60; alert(polygon.type+"n"+ polygon.property +"n"+ polygon.area+"n"+ polygon.perimeter); Initialize Functions in Objects- var obj = {name: "Straight", type: "Angle", getName: function() { alert (this.name);} }; obj.getName(); Initialize String Array- " var course = ["Geometry","Trigonometry","Calculus"]; var course= new Array("Geometry", "Trigonometry", "Calculus"); var list1 = [2,3,5,8]; var list1 = new Array(2,3,5,8); Declare Array Dynamic var arr=new Array(); Array Methods arr.length- Returns the number of elements in an array. arr.concat()- Join several arrays into one. arr.indexOf()- Returns the primitive value of the specified object. arr.join()- Combine elements of an array into a single string and return the string. arr.lastIndexOf()- Gives the last position at which a given element appears in an array. arr.pop()- Removes the last element of an array. arr.push()- Add a new element at the end. arr.reverse()- Sort elements in descending order. arr.shift()- Remove the first element of an array. arr.slice()- Pulls a copy of a portion of an array into a new array. arr.sort()- Sorts elements alphabetically. arr.splice()- Adds elements in a specified way and position. arr.toString()- Converts elements to strings. arr.unshift()- Adds a new element to the beginning. arr.valueOf()- Returns the first position at which a given element appears in an array. Initialization of a 2d Array Static var c[2][3] = {{1, 3, 0}, {-1, 5, 9}}; Set Value Element in 2D Array- c[1][2]=4; Get Value Element in 2D Array- num=c[2][1]; STRINGS var CEO="Markus Hohenwarter"; var str= "javascript"; alert(str.length); length- the length of the string Escape Characters ' - Single quote, " - Double quote, - Backslash r - Carriage return, 0 - NUL character n - A new line characte
  • 5. JAVASCRIPT CHEATSHEET IN GEOGEBRA JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA String Concatenation var nside = 3; alert('Triangles have ' + nside + ' sides.'); String Methods charAt()- Returns a character at a specified position inside a string. charCodeAt()- Gives you the unicode of character at that position. concat()- Concatenates (joins) two or more strings into one. fromCharCode()- Returns a string created from the specified. sequence of UTF-16 code units. indexOf()- Provides the position of the first occurrence of a specified text within a string. lastIndexOf()- Same as indexOf() but with the last occurrence, searching backwards. match()- Retrieves the matches of a string against a search pattern. replace()- Find and replace specified text in a string. search()- Executes a search for a matching text and returns its position. slice()- Extracts a section of a string and returns it as a new string. split()- Splits a string object into an array of strings at a specified position. substr()- Similar to slice() but extracts a substring depended on a specified number of characters. substring()- Also similar to slice() but cannot accept negative indices. toLowerCase()- Convert strings to lower case. toUpperCase()- Convert strings to upper case. valueOf()- Returns the primitive value of a string object. NUMBERS AND MATH Number Properties Math.MAX_VALUE- The maximum numeric value representable in JavaScript. Math.MIN_VALUE- Smallest positive numeric value representable in JavaScript. Math.NaN- The "Not-a-Number" value. Math.NEGATIVE_INFINITY- The negative Infinity value. Math.POSITIVE_INFINITY- Positive Infinity value Number Methods. alert("MAX_VALUE="+Math.MAX_VALUE+ "nMIN_VALUE="+Math.MIN_VALUE+ "nNaN="+Math.NaN+ "nNEGATIVE_INFINITY="+Math.NEGATIVE_INFINITY+ "nPOSITIVE_INFINITY="+Math.POSITIVE_INFINITY); Number Functions var num=Number("2"); num.toExponential()- Returns a string with a rounded number written as exponential notation. num.toFixed()- Returns the string of a number with a specified number of decimals. num.toPrecision()- String of a number written with a specified length. num.toString()- Returns a number as a string. num.valueOf()- Returns a number as a number. Math Properties Math.E- Euler’s number. Math.LN2- The natural logarithm of 2. Math.LN10- Natural logarithm of 10. Math.LOG2E- Base 2 logarithm of E. Math.LOG10E- Base 10 logarithm of E. Math.PI- The number PI. Math.SQRT1_2- Square root of 1/2. Math.SQRT2- The square root of 2. Math Methods and Functions
  • 6. JAVASCRIPT CHEATSHEET IN GEOGEBRA JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA Math.abs(x)- Returns the absolute (positive) value of x Math.acos(x)- The arccosine of x, in radians Math.asin(x)- Arcsine of x, in radians Math.atan(x)- The arctangent of x as a numeric value Math.atan2(y,x)- Arctangent of the quotient of its arguments Math.ceil(x)- Value of x rounded up to its nearest integer. Math.cos(x)- The cosine of x (x is in radians). Math.exp(x)- Value of exponential. Math.floor(x)- The value of x rounded down to its nearest integer. Math.log(x)- The natural logarithm (base E) of x. Math.max(x,y,z,...,n)- Returns the number with the highest value. alert(Math.max(2,3,4)); Math.min(x,y,z, ...,n)- Same for the number with the lowest value. alert(Math.min(-2,-3,-4)); Math.pow(x,y)- X to the power of y. Math.random()- Returns a random number between 0 and 1. Math.round(x)- The value of x rounded to its nearest integer. Math.sin(x)- The sine of x (x is in radians). Math.sqrt(x)- Square root of x. Math.tan(x)- The tangent of an angle. Errors try- Lets you define a block of code to test for errors. catch- Set up a block of code to execute in case of an error. throw- Create custom error messages instead of the standard JavaScript errors. finally- Lets you execute code, after try and catch, regardless of the result. var x =Number(prompt("Enter x")); try{ if(x == "") throw "empty"; //error cases if(isNaN(x)) throw "not a number"; x = Number(x); if(x > 10) throw "too high"; }catch(err) { //if there's an error alert("Input is " + err); //output error }finally{ alert("Done"); //executed regardless of the try / catch result } var ver=parseInt(ggbApplet.getVersion()); try{ if(ver== 5.0){ var A=prompt("Enter Matrix:","0,1,0,1,4; -5,4,2,6,15; -3,2,1,3,8; 2,- 1,0,-2,-5; -1,2,0,0,0"); }else{ var A = "" + ggbApplet.getValueString("Matrix"); }}catch(err){ alert("Error"); }finally{ alert("Version: "+ver); } Setting Dates var d = new Date(); Date()- Creates a new date object with the current date and time Date(2017, 5, 21, 3, 23, 10, 0)- Create a custom date object. The numbers represent year, month, day, hour, minutes, seconds, milliseconds. You can omit anything you want except for year and month. Date("2017-06-23")- Date declaration as a string Pulling Date and Time Values. d.getDate()- Get the day of the month as a number (1-31)
  • 7. JAVASCRIPT CHEATSHEET IN GEOGEBRA JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA d.getDay()- The weekday as a number (0-6) Sunday-0, Monday-1, Tuesday-2, Wednesday-3, Thursday, Friday-5, and Saturday-6. d.getFullYear()- Year as a four-digit number (yyyy) d.getHours()- Get the hour (0-23) d.getMilliseconds()- The millisecond (0-999) d.getMinutes()- Get the minute (0-59) d.getMonth()- Month as a number (0-11) d.getSeconds()- Get the second (0-59) d.getTime()- Get the milliseconds since January 1, 1970 d.getUTCDate()- The day of the month in the specified date according to universal time. Date.now()- Returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC. Date.parse()- Parses a string representation of a date, and returns the number of milliseconds since January 1, 1970. const unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT'); const javaScriptRelease = Date.parse('04 Dec 1995 00:12:00 GMT'); alert("unixTimeZero="+ unixTimeZero+ "nJavaScriptRelease="+javaScriptRelease); d.setDate()- Set the day as a number (1-31) d.setFullYear()- Sets the year (optionally month and day) d.setHours()- Set the hour (0-23) d.setMilliseconds()- Set milliseconds (0-999) d.setMinutes()- Sets the minutes (0-59) d.setMonth()- Set the month (0-11) d.setSeconds()- Sets the seconds (0-59) d.setTime()- Set the time (milliseconds since January 1, 1970) d.setUTCDate()- Sets the day of the month for a specified date according to universal time. var d = new Date(); d.setFullYear(2008, 05, 15); alert(d.getFullYear()+"-"+d.getMonth()+"-"+d.getDate()); ggbAppletMethods var n=ggbApplet.getValue("n"); ggbApplet.setValue("a",1); ggbApplet.evalCommand("l1={}"); ggbApplet.setListValue("l1", i, Math.random() * (vmax - vmin) + vmin); Notepad++ is a text and source code editor to JavaScript. https://notepad-plus-plus.org/downloads/ Use Notepad ++ to create and edit the Geogebra JavaScript code in Language-> J-> JavaScript and after finishing the code copy the code in Geogebra JavaScript and compile the code in some Geogebra object as a button to see if there are errors in the code or if the code works. GeoGebra Scripting https://wiki.geogebra.org/en/Scripting Reference:GeoGebra Apps API https://wik.geogebra.org/en/Reference:GeoGebra_Apps_API JavaScript Tag Search in GeoGebra Web https://www.geogebra.org/search/tags:JavaScript Code Snipets of Javascript in Geogebra https://ww.geogebra.org/m/paxjwmxh
  • 8. JAVASCRIPT CHEATSHEET IN GEOGEBRA JAVASCRIPT CHEATSHEET IN GEOGEBRA PROF. JOSÉ PÉREZ SANABRIA Geogebra Scripting JavaScript Notepad++ Source Code Editor JavaScript