Skip to content
Open

Done #30

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
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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:

Expand All @@ -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.<anonymous> (/home/jmburges/code/labs/js-functions-lab/test.js:1:75)
at Module._compile (module.js:570:32)
Expand Down Expand Up @@ -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:

```
Expand All @@ -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!**
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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
}

4 changes: 2 additions & 2 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ 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)
}



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)
}