Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ / Initialize the hourglass parameters const N = 2 8 ; / / Size of the clock ( adjust as needed ) let upperChamber

// Initialize the hourglass parameters
const N =28; // Size of the clock (adjust as needed)
let upperChamber ="";
let lowerChamber ="";
// Get user inputs for outer border and inner material
const outerBorder = window.prompt("Enter the character for the outer border: ");
const innerMaterial = window.prompt("Enter the character for the inner material: ");
// Construct the initial hourglass
for (let i =0; i <(N/2); i++){
let row =""; // Initialize an empty string for each row
for (let j =0; j < i; j++){
row +=""; // Add spaces to the left of the pattern
}
for (let j =0; j < N -(2*i); j++){
if (j ===0|| j === N -(2*i)-1){
row += outerBorder; // Use "#" for the outer border
} else {
row += innerMaterial; // Add dots inside the pattern
}
}
console.log(row); // Print the row
}
// Construct the lower half of the hourglass
for (let i =(N/2)-2; i >=0; i--){
let row ="";
for (let j =0; j < i; j++){
row +="";
}
for (let j =0; j < N -(2*i); j++){
if (j ===0|| j === N -(2*i)-1){
row += outerBorder; // Use "#" for the outer border
} else {
row +=""; // Add spaces between outer materials
}
}
console.log(row);
}
console.log("");
let currentTime =0;
// Main loop to accept user commands
while (true){
const command = window.prompt("Enter a command (next, prev, nexus, quit):");
if (command === "next"){
// Update the clock for the next hour
const innerRows = currentTime %13; //13 because we reset at 12 hours
// Construct the updated upper chamber string
let updatedUpperChamber ="";
for (let i =0; i <(N/2); i++){
let row =""; // Initialize an empty string for each row
for (let j =0; j < i; j++){
row +=""; // Add spaces to the left of the pattern
}
for (let j =0; j < N -(2*i); j++){
if (j ===0|| j === N -(2*i)-1){
row += outerBorder; // Use "#" for the outer border
} else {
if (row < currentTime){
row +="";
} else {
row += innerMaterial;// Add dots inside the pattern
}
}
}
console.log(row); // Print the row
}
// Construct the lower half of the hourglass
for (let i =(N/2)-2; i >=0; i--){
let row ="";
for (let j =0; j < i; j++){
row +="";
}
for (let j =0; j < N -(2*i); j++){
if (j ===0|| j === N -(2*i)-1){
row += outerBorder; // Use "#" for the outer border
} else {
row +=""; // Add spaces between outer materials
}
}
console.log(row);
}
// Update the current time
currentTime =(currentTime +1)%13; // Increment and reset at 12 hours
// Display the updated clock
console.log(`Hourglass at t=${currentTime}:`);
console.log(updatedUpperChamber);
} else if (command === "prev"){
// if true hourglass/pattern reverses and it does the opposite and fills the top of the hourglass.
} else if (command === "nexus"){
// if true hourglass/pattern reverses to innitial pattern.
} else if (command === "quit"){
console.log("Exiting the hourglass simulation. Goodbye!");
break;
} else {
console.log("Invalid command. Please enter
# # # # # # # # # # # # # # # next, prev, nexus, or quit.");
}
}
fix the code so it is functional please.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

4. How has e-commerce affected business-to-business transactions?

Answered: 1 week ago