Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Tuesday 1 December 2015

Javascript

Javascript is a computer code that can do these thing to your webpage:
1

Monday 30 November 2015

Javascript: Outputting text

I want to output a text into/inside a local paragraf instead of using canvas. How can I do that?

There are 5 steps you need to do:
1. First thing you need to define the paragraph where you want to the text to showed up. Like this:
<p></p>

2. Second thing, you need to insert a span tag into that paragraph tag. Like this below:
<p><span></span></p>

3. Third, you need to give an id to that span tag; just the opening tag, not the closing tag. Like this below:
<p><span id="here"></span></p>

4. Last you need to define below inside your script tag:
<script>
document.getElemenytById("here").innerHTML="<your text>"

</script>

5. Last, finish, run the code.

Warning: Remember to use .innerHTML not .value.

For complete code:
<body>
<p><span id="here"></span></p>

<script>
document.getElementById("here").innerHTML = "<your text>"
</script>
</body>

Javascript: Converting hexadecimal to decimal

I want to convert hexadecimal value (for i.e. "0xff") to a decimal value, how can I do this?

1. Put your hexadecimal-value into a string and then into a variable, like this below:
var a = "0xff" //don't forget the double-quotes

2. then use a function like this:




I usually dealing hexadecimal value with color.
Test

Javascript: Operating on a string

What can we do upon a string?
1. Looking its length
2. Searching index of a string from it
3. Extracting a string from it
4. Inserting a string into it.

Looking for how long / length

a.length


Searching for index
indexOf()
lastIndexOf()

Powerful search using RegEx.

Extracting parts
slice(firstindex, lastindex)

JavaScript Data Types

JavaScript Data Types

In JavaScript there are 5 different data types that can contain values:
  • string
  • number
  • boolean
  • object
  • function
There are 3 types of objects:
  • Object
  • Date
  • Array
And 2 data types that cannot contain values:
  • null
  • undefined

Saturday 21 March 2015

Javascript: array

Array dapat dipandang sebagai rak buku; dalam hal ini rak nilai.

Merujuk array adalah dengan nama dan indexnya.

Pada JS array adalah sebuah object. Objek array punya beberapa metod joining, reversing, and sorting. Objek array mempunyai properti seperti panjang (length).




Tuesday 10 March 2015

Javascript - Function

1. Mempermudah / meringkas penulisan program
2. Bisa menciptakan fungsi reusable. Fungsi reusable adalah fungsi menggunakan fungsi lain.

Komponen
- Nama
- Argumen/parameter
- return
Fungsi harus mempunyai return.


Contoh:
function countapples(bobapples, johnapples)
{
return bobapples+johnapples
}

Contoh reusable:
function avg(a, b)
{
return (countapples(a,b) / 2)
}

Javascript - Collection

Collection adalah koleksi dari properti-properti.

Misalnya seorang pengusaha kos-kosan yang mempunyai beberapa bangunan kos.
Kos1 = {alamat: "Jl. Adisucipto No. 38", jlhkmr: 8}
Kos2 = {alamat: "Jl. H. Subrantas No. 47", jlhkmr: 3}

Misal seorang poligami yang mempunyai istri lebih dari satu
istri1 = {nama: "siti", umur:32, anak:2}
istri2 = {nama: "rini", umur:32, anak:1}

Misal kamu punya banyak properti (tanah atau rumah):
Properti1 = {jenis:"rumah", lokasi:"Jl. Muaratakus nomor 38", Harga_beli=47000000, status: "IMB"}
Properti2 = {jenis:"tanah", lokasi: "Jl. Mataram No. 48", Harga_beli = 177000000, status: "IMB"}
Properti3 = {jenis: "tanah", lokasi: "Jl. Teropong No. 31", Harga_beli = 148000000, status: "IMB"}

Tuesday 17 February 2015

Daftar Input

1. Button
2. Checkbox
3. Color
4. Date
5. Datetime
6. Datetime-local
7. email
8. file
9. hidden
10. image
11. month
12. number
13. password
14. radio
15. range
16. reset
17. search
18. submit
19. text
20. time
21. url
22. week

1. Button

2. Checkbox

3. Color

4. Date

5. Datetime

6. Datetime-local

7. Email

8. File

9. Hidden

10. Image

11. Month

12. Number

13. Password

14. Radio

15. Range

16. Reset

17. Search

18. submit

19. Text

20. Time

21. Url

22. Week

Monday 25 November 2013

Tombol HTML trus dikasih script

Cara membuat tombol html dan kasih script

<html>
<head>
</head>
<body>
<button onclick=greeting()>tombol</button>
<script>

var greeting = function () {
alert ('hello world!')
}

</script>
</body>

apa itu alert? cuma nampilan pop-up browser dengan tulisan hello world!
apa itu var greeting = function() ?


My notes: Javascript

Source referensi: http://www.htmldog.com/guides/javascript/

Kemampuan javascript:
1.  Making stuff hapen => cara menggunakan javascript dan konsol
2. Variable dan data => gimana cara membuat variabel dan bagaimana menggunakannya
3. Doing math => menggunakan variabel untuk menyimpan dan menggunakan angka-angka
4. Logic => bener atau salah
5. Conditional =>
6. Looping =>
7. Functions =>
8. Objects => Properti, method. Menginspeksi obyek-obyek.
9. Array => Mengambil elemen, meletakkan elemen itu kembali. Berapa panjang sebuah potongan string?


 2. Variabel and data (declaring, initialization and assignment)
var surname; (declaring only)
surname = "perjuangan9"; (initialization (giving variable first value))
var apples = 5, pears = 1 (declaring ,init, and assignment)
surname = "perjuangan9"
var jumlahBuah = apples + pears

3. Doing math
Math operator: x, /, +, -

4. Logic
Logic operator:

=== Equality
!== not Equal
> Greater than
< Less than
>=  Combined operations
<= Combined operations

Contoh:
123 === 123
True

123 < 231
True

5. Conditional
5.1 If
if (1 > 2) {alert ('Hello!!!!')}
Hello!!!!

5.2 if-else
if (1 < 2) {alert ('Hello!!!!')}
else {alert ('Boo....')}
 Boo....

6. Looping
6.1 While
var i = 0
while (i <9) { alert (i); i = i + 1; }

Usage: while (final expression) {execution}

6.2 For
for (i = 0; i = 9; i = i + 1;) {alert (i);} 

Usage: for (initialization; condition; final expression) {execution}

7. Function
keyword: function and return

var tambah = function (a, b){
return a + b;
};
alert(tambah(1,2))



8. Objects
Please introduce jedi:

Jedi's name = yoda
jedi's age = 899
jedi's talk = alert ("another sky walk...")

var jedi = { name: 'yoda, age: 899, talk: alert ("another sky walk....")}

8.1 Nested objects


9. Array
Array adalah kumpulan data