The Student Room Group

Idea award silver work resolution code

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”

Scroll to see replies

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:

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?
Reply 2
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:

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?

image.jpg
Reply 3
Also it’s on a loop and I don’t know where to put the code
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 '
Reply 5
Reply 6
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....
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)
Reply 8
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 thisimage.jpg
Reply 9
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....
Original post by Nicole18jc
And how do I fix this code... I’m sorry I’m rubbish at thisimage.jpg


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...


for(i=0; i<movementBlocks.length; i--) {
doMovement(movementBlocks);
}


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. (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 :

i = 0; (i is less than movementBlocks.length -- OK)
doMovement(movementBlocks[0]);
i = i - 1;


Next time
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
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
(edited 5 years ago)
Reply 12
Original post by winterscoming
Array maybe? Still no idea what you mean!

This might help though - https://www.w3schools.com/js/js_arrays.asp

image.jpgHow does this work
Reply 13
image.jpgI need to add a sidebar and a footer
Original post by Nicole18jc
image.jpgI 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:

<?php

?>

Those lines basically give you the beginning and end of the PHP program, so you need to keep them for it to work.
Reply 15
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:

<?php

?>

Those lines basically give you the beginning and end of the PHP program, so you need to keep them for it to work.

image.jpgIt tells me I’m wrong
Original post by Nicole18jc
image.jpgIt 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
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
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 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
image.jpgHow does this work

I can't get past the playSound() part, do you have any idea on how to complete it?

Quick Reply

Latest

Trending

Trending