Javascript beginner help, I need some direction for assignment.

Watch
Gooney82
Badges: 0
Rep:
?
#1
Report Thread starter 3 years ago
#1
Just struggling on certain concepts such as arrays, for and do loops. If anyone can message me then that's class.
0
reply
Eternalflames
Badges: 17
Rep:
?
#2
Report 3 years ago
#2
JavaScriptMaster can you help this guy?
0
reply
ChemistryIsBest
Badges: 2
Rep:
?
#3
Report 3 years ago
#3
get a revision guide, or go onto bitesize gcse computer science.
0
reply
Gooney82
Badges: 0
Rep:
?
#4
Report Thread starter 3 years ago
#4
(Original post by ChemistryIsBest)
get a revision guide, or go onto bitesize gcse computer science.
Haha uni bro
0
reply
ChemistryIsBest
Badges: 2
Rep:
?
#5
Report 3 years ago
#5
(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?
0
reply
itsElliott
Badges: 1
Rep:
?
#6
Report 3 years ago
#6
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
0
reply
username2269391
Badges: 18
Rep:
?
#7
Report 3 years ago
#7
(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
1
reply
INTit
Badges: 17
Rep:
?
#8
Report 3 years ago
#8
Just a correction JavaScript can have arrays containing different types. Most languages you can't though.
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Had lockdown impacted your relationships?

Yes, my partner and I are struggling (16)
7.77%
Yes, my partner and I broke up (14)
6.8%
Yes, it's hard being around my family so much (44)
21.36%
Yes, I'm feeling lonely isolating alone (26)
12.62%
No, nothing has changed (68)
33.01%
No, it's helped improve my relationships (38)
18.45%

Watched Threads

View All