From 54f62107575006e5f08bca0aa0761a359ba39c70 Mon Sep 17 00:00:00 2001 From: "stanciuionelamelania@gmail.com" Date: Thu, 18 Jan 2018 23:28:18 +0000 Subject: [PATCH 1/2] Done. --- README.md | 14 ++++++++------ index.js | 4 ++-- tests.js | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 48e2eda..bbd7db7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Using Conditionals and Multiple Files in JS -We now know how to use conditionals. Now let's use conditionals to test our code for correctness. This is your first step towards how professional developers write software. Professional developers have to test their code for correctness. Instead of constantly clicking around their applications, most developers write additional code, called tests that ensure their code is outputting the right things. +We now know how to use conditionals. Now let's use conditionals to test our code for correctness. This is your first step towards how professional developers write software. Professional developers have to test their code for correctness. Instead of constantly clicking around their applications, most developers write additional code, called tests that ensure their code is outputting the right things. We will eventually explain how to use the professional testing tools but first, let's go over a simple example. @@ -41,7 +41,7 @@ See what we did there? Great! Now run your code again by typing `nodejs index.js var name = "Susan" ``` -Re-run your code and boom! you did it :) +Re-run your code and boom! you did it :) In later steps, we'll be doing our testing in other files. So, for now, let's revert index.js to its original state. Make sure the index.js file is saved and that it looks like this: @@ -64,7 +64,7 @@ Let's open up another javascript file and play around with separating things out /home/jmburges/code/labs/js-functions-lab/test.js:1 (function (exports, require, module, __filename, __dirname) { console.log(name) ^ - + ReferenceError: name is not defined at Object. (/home/jmburges/code/labs/js-functions-lab/test.js:1:75) at Module._compile (module.js:570:32) @@ -96,7 +96,7 @@ Give that a run by typing `nodejs other_file.js` and you should see the name get ### Your Turn - +if(name == Susan) You now know how multiple files interact as well as how `if` statements work. Now you have to write your code to match some specific tests. Open up `tests.js` and you will see two `if` statements. Let's give this a run to start things off by typing `nodejs tests.js`. You should get two messages: ``` @@ -106,7 +106,9 @@ Expected: 70, Received: 74 Now it's your job to modify `index.js` so that when you run `nodejs tests.js` the messages you see logged to the console are: ``` -The name is correct +The name is correct The height is correct ``` -**One note: Capitalization matters and String vs. Numbers matter. Numbers don't have any quotes around them, Strings do have quotes around them!** +name = "Susan" +height = 70 +**One note: Capitalization matters and String vs. Numbers matter. Numbers don't have any quotes around them, Strings do have quotes around them!** diff --git a/index.js b/index.js index 8151607..d7a2e58 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ var name = "Joe" var height = "74" - +name = "Susan" +height = 70 // Don't worry about this module.exports = { name, height } - diff --git a/tests.js b/tests.js index 8da77d0..11dca09 100644 --- a/tests.js +++ b/tests.js @@ -3,7 +3,7 @@ var index = require("./index.js") if (index.name === "Susan") { console.log("The name is correct") } else { - console.log("Expected: Susan, Received: "+index.name) + console.log("Expected: Susan, Received: " + index.name) } @@ -11,5 +11,5 @@ if (index.name === "Susan") { if (index.height === 70) { console.log("The height is correct") } else { - console.log("Expected: 70, Received: "+index.height) + console.log("Expected: 70, Received: " + index.height) } From 140c603388c719a98d0f9e50f7a5e9f1ed4a5ec0 Mon Sep 17 00:00:00 2001 From: "stanciuionelamelania@gmail.com" Date: Thu, 18 Jan 2018 23:30:46 +0000 Subject: [PATCH 2/2] Done. --- index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.js b/index.js index d7a2e58..d9e7bc4 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,22 @@ var name = "Joe" var height = "74" +console.log("Name:") +console.log(name) +console.log("Height:") +console.log(height) +console.log(parseInt(height) + 1 ) +console.log(height) name = "Susan" height = 70 +console.log("Name:") +console.log(name) +console.log("Height:") +console.log(height) + + +console.log(parseInt(height) + 1 ) +console.log(height) // Don't worry about this module.exports = { name, height }