Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Day 3 - Halloween Coding Challenges 2023 - JavaScript

simong1993

Diamond Coder
Staff Team
Guardian
🎃 Spooky Challenge - Day 3 🎃

The JavaScript Jigsaw's Puzzle

In the dimly lit corridors of a haunted mansion, the third spirit challenges you with a puzzle. This ghost, named the JavaScript Jigsaw, has scattered pieces of an array throughout the mansion. Whispers from the shadows give you a riddle:

In the mansion of scripts, where logic intertwines,
An array is fractured, split between lines.
Three pieces are missing, lost in the gloom,
Seek hints from the mansion to seal their doom.
Once complete, the twilight piece you must parse,
To reveal the hidden number and finish this farce.

The Challenge:

You are presented with a fractured array:

JavaScript:
var hauntedArray = [
    {piece: 'dawn', number: 1},
    {piece: 'noon', number: 9},
    // Three pieces of the array are lost in the mansion. Can you find them?
];

Hints from the mansion:

  1. Midnight is darker than dawn, but not the darkest.
  2. Twilight is the absence of light, signifying zero.
  3. Dusk is when day turns to night, marking a second phase.
Your task is to complete the array using the hints and then use JavaScript to find the number associated with the piece named 'twilight'.

Hint: Once the array is complete, spirits suggest using a loop to traverse the array and find the piece you seek.

🕷️ Platform Suggestion: If you wish to conjure this challenge and see it come to life, JSFiddle is the recommended realm. Copy the challenge code into a new fiddle, and let your magic flow. Be sure to peek into the fiddle's built-in console to see the results of your incantations!

🔗 Useful Resource: To understand JavaScript arrays and loops better, you might find W3Schools' JavaScript Arrays Tutorial to be a helpful guide.

The JavaScript Jigsaw's Puzzle Solved:

Mighty code sorcerer, your journey through the haunted mansion has led you to the lair of the JavaScript Jigsaw. With cunning and prowess, you've assembled the shattered array, stitching together the fragmented clues:

JavaScript:
var hauntedArray = [
    {piece: 'dawn', number: 1},
    {piece: 'noon', number: 9},
    {piece: 'midnight', number: 3},
    {piece: 'dusk', number: 2},
    {piece: 'twilight', number: 0}
];

for (var i = 0; i < hauntedArray.length; i++) {
    if (hauntedArray[i].piece === 'twilight') {
        console.log(hauntedArray[i].number);  // The mansion murmurs, revealing "0"
    }
}


As the creaking mansion settles, the ghostly whispers grow louder, guiding you to the solitary number associated with 'twilight'. The mansion's ancient walls echo with a triumphant revelation: the number "0".

With the JavaScript Jigsaw's enigma unraveled, you've brought light to the mansion's darkness. But remember, the night is long, and many more challenges await...
 
Last edited:
Happy (or maybe scary) Halloween, here is like my answer.
1-16=-15, Twilight is - 15.
JavaScript:
var hauntedArray = [
    {piece: 'dawn', number: 1},
    {piece: 'noon', number: 9},
    {piece: 'dusk', number: 1},
    {piece: 'midnight', number: -7},
    {piece: 'twilight', number: -15}
    // Three pieces of the array are lost in the mansion. Can you find them?
];
let indexMaybe = hauntedArray.length-1;
while (indexMaybe != -1) {
    if (hauntedArray[indexMaybe].piece=='twilight') {
        console.log(hauntedArray[indexMaybe].number);
        break;
    }
    indexMaybe-=1;
}
//X E
X E.
 
Happy (or maybe scary) Halloween, here is like my answer.
1-16=-15, Twilight is - 15.
JavaScript:
var hauntedArray = [
    {piece: 'dawn', number: 1},
    {piece: 'noon', number: 9},
    {piece: 'dusk', number: 1},
    {piece: 'midnight', number: -7},
    {piece: 'twilight', number: -15}
    // Three pieces of the array are lost in the mansion. Can you find them?
];
let indexMaybe = hauntedArray.length-1;
while (indexMaybe != -1) {
    if (hauntedArray[indexMaybe].piece=='twilight') {
        console.log(hauntedArray[indexMaybe].number);
        break;
    }
    indexMaybe-=1;
}
//X E
X E.

on the right path 🙂
  1. Midnight is darker than dawn, but not the darkest.
  2. Twilight is the absence of light, signifying zero.
  3. Dusk is when day turns to night, marking a second phase.
Twilight is 0, the clue is at the end.
Dusk is 2, the clue is at the end, the second phase
midnight is darker then dawn so bigger then 1 but it cant be 2 so it must be 3
 
JavaScript:
let hauntedArray = [
  {piece: 'twilight', number: 0},
  {piece: 'midnight', number: 0.5},
  {piece: 'dawn', number: 1},
  {piece: 'dusk', number: 2},
  {piece: 'noon', number: 9},
  // Three pieces of the array are lost in the mansion. Can you find them?
];

for (let i = 0; i < 5; i++) {
  if (JSON.stringify(hauntedArray[i]) === JSON.stringify({piece: 'twilight', number: 0})) {
      console.log(hauntedArray[i])
    break;
  }
}
 
Back
Top Bottom