Turn on thread page Beta

Javascript beginner help, I need some direction for assignment. watch

    • Thread Starter
    Offline

    0
    ReputationRep:
    Just struggling on certain concepts such as arrays, for and do loops. If anyone can message me then that's class.
    Offline

    17
    ReputationRep:
    JavaScriptMaster can you help this guy?
    Offline

    2
    ReputationRep:
    get a revision guide, or go onto bitesize gcse computer science.
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by ChemistryIsBest)
    get a revision guide, or go onto bitesize gcse computer science.
    Haha uni bro
    Offline

    2
    ReputationRep:
    (Original post by Gooney82)
    Haha uni bro
    because you've written beginner in the title I assumed this was GCSE level. How do you not understand arrays and iterations?
    Offline

    1
    ReputationRep:
    It would be best for your to described what you don't understand? I have not gone through any school circiular on Computer Science so I'm not sure what your stuck, however I am a self taught programmer.

    Is it the idea/concept of them or is it a particular question/application
    Offline

    18
    ReputationRep:
    (Original post by Eternalflames)
    JavaScriptMaster can you help this guy?
    Well Of course!

    "Just struggling on certain concepts such as arrays, for and do loops"

    K, lets start with arrays:

    1) Arrays are a group of variables
    2) All the variables in an array are of the same type, ie. Array of integers or an array of strings, you can't have integers and strings in the same array.
    3) You can pick out a variable within an array by a process called "indexing" which means each variable has an index which defines it's position in the array.
    4) Indexing starts at 0 and goes up by 1 for each element in the array

    here is how you declare an array in JS:

    Code:
    var emptyArray = [];
    var fullArray = ["fred", "steve", "will"];
    The first example will declare an empty array, whereas the second example will create an array of 3 strings.

    indexing example:
    Code:
    var firstElement = fullArray[0];
    console.log(firstElement);
    
    fullArray[3] = "pete";
    Using the first line of code, we are reading from the first element of the array by adding the [0] index, to read the second element you would add the [1] index and so on...

    On the 3rd line you see indexing go the other way, in this example we are writing to the array by giving an index, after line 3 the array will contain 4 names and the last one will be "pete".

    If you just want to add something to the end of an array, you can do so without having to index, see below

    Code:
    fullArray.push("Joe";);
    Nearly every programming language has an "Array.push()" method...

    One last thing with arrays: don't want to twist your head but an array can also contain more arrays inside it, this is known as a 2-dimensional array and it looks like the following:

    Code:
    var 2dArray = 
    [
    [1, 0, 1],
    [1, 1, 1],
    [0, 0, 1]
    ];
    As you can see, it makes sense to visualize a 2D array as a square, people call this a map or a matrix. this sort of thing is the basis of 2D graphics, Mario was first drawn as a 2D array of bits, hence the name bitmap. And yes you can also have 3-Dimensional arrays which are used in 3D graphics.

    I'll update this later when I get some more time. happy coding for now
    Offline

    17
    ReputationRep:
    Just a correction JavaScript can have arrays containing different types. Most languages you can't though.
 
 
 
Reply
Submit reply
Turn on thread page Beta
Updated: December 1, 2016

University open days

  1. University of Bradford
    University-wide Postgraduate
    Wed, 25 Jul '18
  2. University of Buckingham
    Psychology Taster Tutorial Undergraduate
    Wed, 25 Jul '18
  3. Bournemouth University
    Clearing Campus Visit Undergraduate
    Wed, 1 Aug '18
Poll
How are you feeling in the run-up to Results Day 2018?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.