Welcome to an exciting 2-hour lab experience! You are a crew member aboard the spaceship "CodeRunner," which is lost in a galaxy far, far away due to a navigation system failure. To get back to Earth, you'll need to solve a series of coding challenges using JavaScript. Are you ready to embark on this adventurous journey? Let's start!
The "CodeRunner" spaceship is out of power! The first task in getting yourself back home is to restart the ship's power generator. The generator is coded to restart when a specific sequence of codes is executed. You'll need to find that sequence and initiate the power-up sequence.
- Initialize the spaceship's systems.
- Generate the secret sequence code required for starting the power generator.
- Validate the generated sequence and restart the power generator.
You need to define a JavaScript object to simulate the spaceship's systems.
const spaceship = {
powerGenerator: false,
navigationSystem: false,
communicationSystem: false
};
Write a function that returns a random sequence of numbers between 1 and 10. This sequence will be the "key" to restarting the power generator.
function generateSequence() {
// Your code here
}
Write another function that takes a sequence as an argument. If the sequence matches the secret sequence, set powerGenerator
to true
.
function validateSequence(sequence) {
// Your code here
}
Now, generate a secret sequence and use your validate function to restart the power generator.
const secretSequence = generateSequence();
console.log("Secret Sequence Generated: ", secretSequence);
validateSequence(secretSequence);
console.log("Current Spaceship Status: ", spaceship);
- Add more complexity to the secret sequence generator.
- Add a countdown timer that simulates the urgency of restarting the generator.
Once you successfully complete Section 1, your spaceship's power generator will restart, enabling you to proceed to Section 2, where you'll work on the navigation system.
Remember, time is of the essence, and you have to get back home!