Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions tutorials/01-basic-syntax/code-execution/exercises/practice.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
// JAVA
// JAVASCRIPT

word = word + "PT";
word = word + "VA";
word = word + "RI";
word = word + "SC";
let word = "";

word = word + "JA";
word = word + "VA";

let word = "";
console.log(word);

word = word + "SC";
word = word + "PT";
word = word + "RI";

console.log(word);


// Run the file before moving on to ensure you get the expected result.

/** DATA MANIPULATION **/
Expand All @@ -35,13 +39,23 @@ console.log(word);

// IMPORTANT: Do not edit the 6 existing lines of code; add NEW lines of code only.


let num1 = 56;
let num2 = 121;
let num3 = 73;
let num4 = 24;
let num5 = 88;
let num6 = 95;

num1 = num1-5;
num2 = num2+1;
num3 = num3+1;
num4 = num4-5;
num5 = num5-5;
num6 = num6+1;

console.log(num1+num2+num3+num4+num5+num6);

// All done? Great job! Understanding how JavaScript executes and evaluates code is
// important. Keep these principles in mind as you solve future problems!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ let fuel = 90;
TODO: Un-comment the line below and run the program to see the error message,
then fix the code and re-run to verify.
*/
// console.log("Fuel level is " fuel + '%");
console.log("Fuel level is "+fuel +"%");

/** EXERCISE 2: THE RUNTIME CRASH **/

/*
TODO: Un-comment the line below and run the program to see the error message,
then fix the code and re-run to verify.
*/
// console.log(navCoordinate);

let navCoordinate = "Sector-7G";
console.log(navCoordinate);

/** EXERCISE 3: THE TYPO BLUNDER **/

Expand All @@ -33,7 +34,7 @@ let oxygen = 100;
TODO: Un-comment the line below and run the program to see the error message,
then fix the code and re-run to verify.
*/
// console.log(oxygen.toString);
console.log(oxygen.toString());

// HINT: toString is not a property — it's a method! Do a little research
// on the difference if you need to.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ console.log("--- INITIALIZING MISSION CONTROL ---");
TODO: Un-comment the line below and run the program to see the error message,
then fix the code and re-run to verify.
*/
// let pilotName = input.question("Enter Pilot Name: ";
let pilotName = input.question("Enter Pilot Name: ");

// --- 2. ENGINE STATUS CHECK ---

Expand All @@ -31,13 +31,15 @@ let checkEngines = input.question("Perform engine diagnostic? (Y/N): ");
TODO: Un-comment the if/else statement below and run the program to see the error message,
then fix the code and re-run to verify.
*/
// if (checkEngines === "Y") {
// console.log(`Engine Health at ${engineHealth}%`);
// engineStatus = "Ready";
// let engineHealth = 100;
// } else {
// console.log("Skipping engine diagnostic...");
// }

if (checkEngines === "Y" || checkEngines === "y") {
let engineHealth = 100;
console.log(`Engine Health at ${engineHealth}%`);
engineStatus = "Ready";

} else {
console.log("Skipping engine diagnostic...");
}

// --- 3. CARGO WEIGHT CALCULATION ---

Expand All @@ -47,15 +49,15 @@ console.log("\n--- CARGO BAY CHECK ---");
TODO: Un-comment the line below and run the program to see the error message,
then fix the code and re-run to verify.
*/
// let crateCount = input.questionInt "How many crates are being loaded? " ;
let crateCount = input.questionInt("How many crates are being loaded? ") ;

/*
TODO: Un-comment the three lines of code below and run the program to see the error message,
then fix the code and re-run to verify.
*/
// let weightPerCrate = 50;
// let totalWeight = crateCount * weightPerCrate;
// console.log('Total Cargo Weight: ${totalWeight}kg');
let weightPerCrate = 50;
let totalWeight = crateCount * weightPerCrate;
console.log(`Total Cargo Weight: ${totalWeight}kg`);

// --- 4. FINAL LAUNCH LOGIC ---

Expand All @@ -65,7 +67,9 @@ console.log("\n--- FINAL STATUS ---");
TODO: Un-comment the if/else statement below and run the program to see the error message,
then fix the code and re-run to verify.
*/
// if (engineStatus === "Ready" && totalWeight < 1000)
// console.log("All systems GO. Launching " + pilotName + into orbit!");
// } else {
// console.log("Launch ABORTED. Check engine status or cargo weight.");

if (engineStatus === "Ready" && totalWeight < 1000){
console.log("All systems GO. Launching " + pilotName + "into orbit!");
} else {
console.log("Launch ABORTED. Check engine status or cargo weight.");
}