Nicole18jc
Badges: 4
Rep:
?
#1
Report Thread starter 1 year ago
#1
I’m stuck on functions 2 and I have no idea how to “use the lifeSupportOn() function” I don’t know how to “pass an object into it”
0
reply
winterscoming
Badges: 19
Rep:
?
#2
Report 1 year ago
#2
(Original post by Nicole18jc)
I’m stuck on functions 2 and I have no idea how to “use the lifeSupportOn() function” I don’t know how to “pass an object into it”
I don't know what the problem looks like that you're trying to solve, but is it just terminology that's confusing you?

'use the lifeSupportOn() function' means getting the program to actually run that function, which is just a single line of code like this:
Code:
lifeSupportOn()
'pass an object into it' - that means putting something from the program in-between the ( and ) brackets. Does it tell you what the object is?
1
reply
Nicole18jc
Badges: 4
Rep:
?
#3
Report Thread starter 1 year ago
#3
(Original post by winterscoming)
I don't know what the problem looks like that you're trying to solve, but is it just terminology that's confusing you?

'use the lifeSupportOn() function' means getting the program to actually run that function, which is just a single line of code like this:
Code:
lifeSupportOn()
'pass an object into it' - that means putting something from the program in-between the ( and ) brackets. Does it tell you what the object is?
Name:  image.jpg
Views: 514
Size:  96.1 KB
0
reply
Nicole18jc
Badges: 4
Rep:
?
#4
Report Thread starter 1 year ago
#4
Also it’s on a loop and I don’t know where to put the code
0
reply
winterscoming
Badges: 19
Rep:
?
#5
Report 1 year ago
#5
(Original post by Nicole18jc)
Also it’s on a loop and I don’t know where to put the code
Yep, it's in a loop - Here's what's happening with the object though:
- The top of the program has a list-of-objects, called 'rooms'.
- There's a variable called 'i' which is a number. 'i' starts at zero, then has 1 added to it every time the loop cycles around.
- Each time the loop cycles, variable 'i' is used alongside 'rooms' -- so 'rooms[i]' gives you each object in the list.

So:
For the first cycle of the loop, i is 0. The object at position 0 is bridge, so rooms[i] happens to be the bridge object.
For the second cycle of the loop, i is 1. The object at position 1 is lab, so rooms[i] happens to be lab object.
etc.

-- So rooms[i] will already give you an object. But the loop is just kind of doing nothing with the object at the moment.

So the problem sounds like you're being asked to replace this line inside the loop
Code:
rooms[i];
with this line inside the loop instead:
Code:
lifeSupportOn(rooms[i]);
if you read that in plain English it means 'use the lifeSupportOn function for the rooms[i] object' (basically, running the function every time the loop cycles with the 'next' object from the list each time, repeating until it reaches the end of the list).
0
reply
Nicole18jc
Badges: 4
Rep:
?
#6
Report Thread starter 1 year ago
#6
(Original post by winterscoming)
Yep, it's in a loop - Here's what's happening with the object though:
- The top of the program has a list-of-objects, called 'rooms'.
- There's a variable called 'i' which is a number. 'i' starts at zero, then has 1 added to it every time the loop cycles around.
- Each time the loop cycles, variable 'i' is used alongside 'rooms' -- so 'rooms[i]' gives you each object in the list.

So:
For the first cycle of the loop, i is 0. The object at position 0 is bridge, so rooms[i] happens to be the bridge object.
For the second cycle of the loop, i is 1. The object at position 1 is lab, so rooms[i] happens to be lab object.
etc.

-- So rooms[i] will already give you an object. But the loop is just kind of doing nothing with the object at the moment.

So the problem sounds like you're being asked to replace this line inside the loop
Code:
rooms[i];
with this line inside the loop instead:
Code:
lifeSupportOn(rooms[i]);
if you read that in plain English it means 'use the lifeSupportOn function for the rooms[i] object' (basically, running the function every time the loop cycles with the 'next' object from the list each time, repeating until it reaches the end of the list).
Thank you so so much x
0
reply
Nicole18jc
Badges: 4
Rep:
?
#7
Report Thread starter 1 year ago
#7
(Original post by Nicole18jc)
Thank you so so much x
Also what did I use to store the objects x something to do with ar....
0
reply
winterscoming
Badges: 19
Rep:
?
#8
Report 1 year ago
#8
(Original post by Nicole18jc)
Also what did I use to store the objects x something to do with ar....
Not sure what you mean? Something about arrays?

(sorry, I used the word 'list' above, I should have used 'array' instead.. pretty much the same thing though)
0
reply
Nicole18jc
Badges: 4
Rep:
?
#9
Report Thread starter 1 year ago
#9
(Original post by winterscoming)
Not sure what you mean? Something about arrays?

(sorry, I used the word 'list' above, I should have used 'array' instead.. pretty much the same thing though)
And how do I fix this code... I’m sorry I’m rubbish at thisName:  image.jpg
Views: 752
Size:  89.4 KB
0
reply
Nicole18jc
Badges: 4
Rep:
?
#10
Report Thread starter 1 year ago
#10
(Original post by Nicole18jc)
Thank you so so much x
Also what did I use to store the objects x something to do with ar....
0
reply
winterscoming
Badges: 19
Rep:
?
#11
Report 1 year ago
#11
(Original post by Nicole18jc)
And how do I fix this code... I’m sorry I’m rubbish at thisName:  image.jpg
Views: 752
Size:  89.4 KB
You need to see what's wrong with it to fix it... the best way to see what's wrong is to trace it step-by-step...

Code:
for(i=0; i<movementBlocks.length; i--) {
  doMovement(movementBlocks[i]);
}
Translate that into what it means first:

Firstly - Before the loop begins, set 'i' to a value of 0.

Then, keep Cycling the loop:
1) if 'i' has a value less than the length of the movementBlocks array carry on. (length is presumably a number higher than zero)
2) call the doMovement function using the object at movementBlocks[i]. (same as before)
4) i-- happens at the end andmeans subtract 1 from the value of 'i'. (equivalent to i = i - 1)

Remember that movementBlocks is an array (list). The rule of arrays/lists is that the objects are always numbered because the numbers tell you what the position of the object is (like an index number in a book)

So look at what happens in the first cycle :
Code:
i = 0;  (i is less than movementBlocks.length -- OK)
doMovement(movementBlocks[0]);
i = i - 1;
Next time
Code:
i = -1; //  (i is less than movementBlocks.length -- OK)
doMovement(movementBlocks[-1]);  
i = i - 1;

That's going to be a problem because movementBlocks can't have a negative number for an object.

You should be able to see your loop from earlier (which was right) and see the difference
0
reply
winterscoming
Badges: 19
Rep:
?
#12
Report 1 year ago
#12
(Original post by Nicole18jc)
Also what did I use to store the objects x something to do with ar....
Array maybe? Still no idea what you mean!

This might help though - https://www.w3schools.com/js/js_arrays.asp
Last edited by winterscoming; 1 year ago
0
reply
Nicole18jc
Badges: 4
Rep:
?
#13
Report Thread starter 1 year ago
#13
(Original post by winterscoming)
Array maybe? Still no idea what you mean!

This might help though - https://www.w3schools.com/js/js_arrays.asp
Name:  image.jpg
Views: 565
Size:  82.2 KBHow does this work
0
reply
Nicole18jc
Badges: 4
Rep:
?
#14
Report Thread starter 1 year ago
#14
Name:  image.jpg
Views: 465
Size:  76.1 KBI need to add a sidebar and a footer
0
reply
winterscoming
Badges: 19
Rep:
?
#15
Report 1 year ago
#15
(Original post by Nicole18jc)
Name:  image.jpg
Views: 465
Size:  76.1 KBI need to add a sidebar and a footer
You weren't too far off first time. It looks like you only need to add stuff in-between these lines keeping all the other stuff which is there already, including all the HTML in the same place too:
Code:
<?php 

?>
Those lines basically give you the beginning and end of the PHP program, so you need to keep them for it to work.
0
reply
Nicole18jc
Badges: 4
Rep:
?
#16
Report Thread starter 1 year ago
#16
(Original post by winterscoming)
You weren't too far off first time. It looks like you only need to add stuff in-between these lines keeping all the other stuff which is there already, including all the HTML in the same place too:
Code:
<?php 

?>
Those lines basically give you the beginning and end of the PHP program, so you need to keep them for it to work.
Name:  image.jpg
Views: 435
Size:  101.0 KBIt tells me I’m wrong
0
reply
winterscoming
Badges: 19
Rep:
?
#17
Report 1 year ago
#17
(Original post by Nicole18jc)
Name:  image.jpg
Views: 435
Size:  101.0 KBIt tells me I’m wrong
OK I suppose you were a bit further away, but basically, you don't need to use all those extra symbols around the functions - just use the functions that it gives you as-is, inside the PHP start/end, so all you need for the sidebar is
Code:
get_sidebar();
without all the extra <? i//?> symbols around the functions. (still need it on those lines which start and end the PHP program of course)
t
0
reply
winterscoming
Badges: 19
Rep:
?
#18
Report 1 year ago
#18
Also, it's probably worth doing some tutorials to get the basic syntax of PHP, try some of these:

https://www.w3schools.com/php7/default.asp

Programming languages aren't very easy to figure out by yourself when you're just staring at things, you really need to follow some kind of book or tutorial and practice a bit so that at least the syntax and structure of the language makes sense and that you can see what the code is doing!
0
reply
sebcalvert
Badges: 1
Rep:
?
#19
Report 1 year ago
#19
(Original post by winterscoming)
Also, it's probably worth doing some tutorials to get the basic syntax of PHP, try some of these:

https://www.w3schools.com/php7/default.asp

Programming languages aren't very easy to figure out by yourself when you're just staring at things, you really need to follow some kind of book or tutorial and practice a bit so that at least the syntax and structure of the language makes sense and that you can see what the code is doing!
(Original post by Nicole18jc)
Name:  image.jpg
Views: 565
Size:  82.2 KBHow does this work
I can't get past the playSound() part, do you have any idea on how to complete it?
1
reply
SubToMavicOnYT
Badges: 4
Rep:
?
#20
Report 9 months ago
#20
(Original post by winterscoming)
Yep, it's in a loop - Here's what's happening with the object though:
- The top of the program has a list-of-objects, called 'rooms'.
- There's a variable called 'i' which is a number. 'i' starts at zero, then has 1 added to it every time the loop cycles around.
- Each time the loop cycles, variable 'i' is used alongside 'rooms' -- so 'rooms[i]' gives you each object in the list.

So:
For the first cycle of the loop, i is 0. The object at position 0 is bridge, so rooms[i] happens to be the bridge object.
For the second cycle of the loop, i is 1. The object at position 1 is lab, so rooms[i] happens to be lab object.
etc.

-- So rooms[i] will already give you an object. But the loop is just kind of doing nothing with the object at the moment.

So the problem sounds like you're being asked to replace this line inside the loop
Code:
rooms[i];
with this line inside the loop instead:
Code:
lifeSupportOn(rooms[i]);
if you read that in plain English it means 'use the lifeSupportOn function for the rooms[i] object' (basically, running the function every time the loop cycles with the 'next' object from the list each time, repeating until it reaches the end of the list).
Thank you so much!
1
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

Should there be a new university admissions system that ditches predicted grades?

No, I think predicted grades should still be used to make offers (643)
33.47%
Yes, I like the idea of applying to uni after I received my grades (PQA) (814)
42.37%
Yes, I like the idea of receiving offers only after I receive my grades (PQO) (378)
19.68%
I think there is a better option than the ones suggested (let us know in the thread!) (86)
4.48%

Watched Threads

View All