Note that there are some explanatory texts on larger screens.

plurals
  1. POlearnyounode 'My First I/O' example
    primarykey
    data
    text
    <p>This program puzzles me. The goal of this program is to count the number of newlines in a file and output it in command prompt. <a href="http://nodeschool.io/#learn-you-node">Learnyounode</a> then runs their own check on the file and sees if their answer matches your answer.</p> <p>So I start with the answer : </p> <pre><code>var fs = require('fs'); var filename = process.argv[2]; file = fs.readFileSync(filename); contents = file.toString(); console.log(contents.split('\n').length - 1); </code></pre> <p>learnyounode verifies that this program correctly counts the number of new lines. But when I change the program to any of the following, it doesn't print out the same number as learnyounode prints out.</p> <pre><code>file = fs.readFileSync(C:/Nick/test.txt); file = fs.readFileSync(test.txt); </code></pre> <p>Shouldn't nodejs readFileSync be able to input an address and read it correctly?</p> <p>Lastly, this program is supposed to print out the # of newlines in a program. Why does both the correct program and learnyounode print out the same number that is different from the amount of newlines everytime I run this program? </p> <p>For example, the number of newlines in test.txt is 3. But running this program prints out a different number everytime, like 45, 15, 2, etc. Yet at the same time, it is verified as a correct program by learnyounode because both their answers match! What is going on?</p> <p>EDIT: test.txt looks like this</p> <pre><code>ok testing 123 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload