21 Day Coding Challenge

Code 21. Confusing

#1

Hi folks,

Can someone who understands the last challenge give me some guidance on how to complete it?
I’ve done some coding but I know where I’m stuck.
If someone can help me, that would be really appreciative.

#2

where are you stuck?

#3
  • for the most part the idea is to break it down into stages.
  • remember to parse in a string when calling the broadcast function
  • and when calling the parseInt function, keep in mind that you are parsing in a hexadecimal number. so you may need to google the number you should parse as a second argument in your call
  • and finally remember to call your function to return home at the end
#4

Me too.
What does this line mean?

You’ll need to save the response from each of these calls into it’s own variable

#5
function returnToEarth() {
        let x = broadcast("x");
        let y = broadcast("y");
        let z = broadcast("z");

        let messageX = decodeMessage(parseInt(x, x));
        let messageY = decodeMessage(parseInt(y, y));
        let messageZ = decodeMessage(parseInt(z, z));
        
        navigation.x = messageX;
        navigation.y = messageY;
        navigation.z = messageZ;
    }

    returnToEarth();

This is all I’ve got @JesseKai

I’m not sure what to do in the parseInt part.

#6

did you try parseInt(x,16)

#7

@Sinduja like this?

 let messageX = decodeMessage(parseInt(x, 16));
 let messageY = decodeMessage(parseInt(y, 16));
 let messageZ = decodeMessage(parseInt(z, 16));
#8

yes Thats what i tried but doesnt seem to work

#9

nope it doesn’t work.

#10

why am I getting this error though?

Your code could not run. Hint: "message.replace is not a function"

#11

decodeMEssage takes a string as a input right?

#12

I think it does. Don’t mind the other part of this comment.

#13
  • Decode the returned message using the decodeMessage() function you wrote earlier
  • Change the decoded hex-coordinate to an integer using parseInt()

The result you get from decodeMessage() is the hex-coordinate, so you decode first, then parseInt.

let messageX = parseInt(decodeMessage(x), base);

base is the radix that represents hexadecimal.

2 Likes
#14

I agree and upvote @sengakae

#15

Don’t forget to call returnToEarth() as well!

1 Like
#16

Thanks a lot, solved it. ALL DONE! Thanks to everyone! Cheers.

2 Likes
#17

the order is wrong. put the decodeMessage function inside parseInt and then the base to make it hexidemical which is 16. and then you should use the decodeMessage() to decode the response of each broadcast function. so put that into decodeMessage function.

hope this helps

1 Like
#18

sorry I am still confused decodeMEssage takes a string .can we pass the result of the broadcast fucntion directly to the decodeMEssage

#19

solved tthis thanks a ton:)