Javascript

From Hack Wars Wiki

Jump to: navigation, search

Contents

[edit] Genral Functions

Function Description
alert() not supported in HackWars because of abuse
setTimeout() not supported

[edit] Supported Events

The following are javascript events that have been tested in the Hackwars browser. The list will be filling out over the next few days as more are tested.

Event Tags that support it Tags that do not
onclick <a> <img> <input type="button"> <input type="submit"> <input type="reset"> <div> <span> <input type="radio"> <input type="text"> <input type="checkbox"> <select>
onmouseover <a> <span> <div> <img>
onmouseout <div> <span>
onload <body>  -

[edit] Supported Event Attributes

The following event attributes are supported for
<div onclick="functionname(parameters,event,moreParameters)">
  • supported: altKey, button, clientX, clientY, ctrlKey, shiftKey, type
  • not supported: metaKey, relatedTarget, screenX, screenY, bubbles, cancelable, currentTarget, eventPhase, target, timeStamp

[edit] String Object

The string object lets you work with text.


[edit] Properties

Property Description
constructor A reference to the function that created the object
length Returns the number of characters in a string
prototype Allows you to add properties and methods to the object


[edit] Methods

Method Description
anchor() Creates an HTML anchor
big() Displays a string in a big font
blink() Displays a blinking string
bold() Displays a string in bold
charAt() Returns the character at a specified position
charCodeAt() Returns the Unicode of the character at a specified position
concat() Joins two or more strings
fixed() Displays a string as teletype text
fontcolor() Displays a string in a specified color
fontsize() Displays a string in a specified size
fromCharCode() Takes the specified Unicode values and returns a string
indexOf() Returns the position of the first occurrence of a specified string value in a string
italics() Displays a string in italic
lastIndexOf() Returns the position of the last occurrence of a specified string value, searching backwards from the specified position in a string
link() Displays a string as a hyperlink
match() Searches for a specified value in a string
replace() Replaces some characters with some other characters in a string
search() Searches a string for a specified value
slice() Extracts a part of a string and returns the extracted part in a new string
small() Displays a string in a small font
split() Splits a string into an array of strings
strike() Displays a string with a strikethrough
sub() Displays a string as subscript
substr() Extracts a specified number of characters in a string, from a start index
substring() Extracts the characters in a string between two specified indices
sup() Displays a string as superscript
toLowerCase() Displays a string in lowercase letters
toUpperCase() Displays a string in uppercase letters
toSource() Represents the source code of an object
valueOf() Returns the primitive value of a String object



[edit] Operators

Comparison Operators

Comparison operators are used in logical statements to determine equality or difference between variables or values.

Operator Symbol Supported? Description
Equal to == Yes the numbers or objects or values must be equal
Exactly equal to === Yes the numbers or objects or values must be exactly equal
Not equal too  != Yes the numbers or objects or values must not be equal
Greater than > Yes number on the left must be greater than the number on the right - this also works with strings and values
Less than < Yes number on the left must be less than the number on the right - this also works with strings and values
Greater than or equal to >= Yes number on the left must be greater than or equal to the number on the right - this also works with strings and values
Less than or equal to <= Yes number on the left must be less than or equal to the number on the right - this also works with strings and values



Logical Operators

Logical operators are used to determine the logic between variables or values.

Operator Symbol Supported? Description
AND && Yes logical AND (both statements must be true)
OR || Yes logical OR (either statement must be true)
NOT (both statements must be true)  ! Semi logical NOT (the statement must not be true). Only works by grouping it, exmple: if (!(x ==0))



Arithmetic Operations

Arithmetic operators are used to perform arithmetic between variables and/or values.

Operator Symbol Supported? Description
Add + Yes adds two numbers or appends two strings - if more than one type of variable is appended, including a string appended to a number or vice-versa, the result will be a string
Subtract - Yes subtracts the second number from the first
Multiply * Yes multiplies two numbers
Divide / Yes divides the first number by the second
Modulo  % Yes finds the remainder from the devision of two numbers. e.f 7/3 = 1, 9/3 = 0, 8/3 = 2
Increment ++ Yes increment the number
Decrement -- Yes decrement the number



Assignment Operators

Assignment operators are used to assign values to JavaScript variables.

Operator Symbol Supported? Description
Equals = Yes assigns the value on the right to the object on the left
+= Yes the object on the left = the object on the left + the value on the right - this also works when appending strings
-= Yes
*= Yes
/= Yes
 %= Yes



Conditional Operator

Operator Symbol Supported? Description
Ternary  ?: No is part of the basic syntax for a basic conditional expressions. Is similar to the conditional expression (if-then-else). (condition)? if true: if false;

[edit] external Sources

Tutorials: http://www.w3schools.com/JS/default.asp

References: http://www.w3schools.com/jsref/default.asp http://www.howtocreate.co.uk/tutorials/javascript/operators

Personal tools