This is very strange. The problem doesn’t even start with a function kind of already filled out. How are we supposed to know where the computer is going to input like on codewars? I know this is right if there were a function filled out already.
Name of problem: Practice makes us perfect. My code is below. (:
function weeks(problem) {
let numberOfWeeks = 0;
for (let i = 0; i < problem.length; i++) {
if (problem >= 10) {
numberOfWeeks = numberOfWeeks + problem[i];
}
}
return numberOfWeeks;
}
hello,
you don’t actually have a javascript question, more of a “how do I use the CodeChef website” question.
But that’s okay. Here’s what you need to do:
Go back to the description of the exercise, then read it.
Some of things you may want to read include:
the section titled " Input Format"
the section titled “Output Format”
the section titled “Constraints”
Perhaps you neglected to scroll down to review them the first time?
(they mention for eg that the function you are to write needs 4 inputs)
still don’t understand what function to start with for the inputs the computer will input. Maybe I DID read it but didn’t understand still? That’s why I am asking (:
I’m not sure how to advise you because I don’t personally know you but if you are interested in a professional job as a developer, you should consider trying to work through vague descriptions of code requirements. After all, people are quite vague. (just look at this conversation we are having. We barely understand each other. )
There is a single line of input, with 4 integers p1,p2,p3,p4. What does single line have to do with anything? The way this problem is worded is really throwing me off. It doesn’t get to the point and give you everything you need
this would be correct. but since the problem did not come with a function already written, it threw me off. can’t even log the computer’s input to the console to see what the input is lol.
function weeks(problem) {
let numberOfWeeks = 0;
for (let i = 0; i < problem.length; i++) {
if (problem >= 10) {
numberOfWeeks = numberOfWeeks + problem[i];
}
}
return numberOfWeeks;
}
I found one of the submissions, and I have NO idea how this is the right answer… Are we supposed to program the actual test?
let reader = new BufferedReader( new InputStreamReader(System['in']) );
let firstLine = reader.readLine();
let num = firstLine.split(' ');
let arr = [];
for( i = 0; i < 4; i++ ) {
arr.push(parseInt(num[i]));
}
let output = 0;
for( index = 0; index < arr.length; index ++) {
if(arr[index] >= 10) {
output += 1;
}
}
print(output);
This is not like you are used to, in which you write a function that get an input
here your input is a stream of data, let’s say it is sort like a file. You need to read that, calculate the requested result, and output the result to a stream of data
The instructions do not say anything about creating a function. The instructions state you must take the input and create a specific output. I used NodeJS as I am more familiar with how to process input as this site appears to feed it to the user.
For NodeJS, you would do something like:
process.stdin.resume();
process.stdin.setEncoding('utf8');
let input = '';
process.stdin.on('data',chunk => input += chunk);
process.stdin.on('end',()=> {
/*
write your code here referencing the `input` variable
as the actual input received
*/
console.log(result);// result would be the output expected
})
A slightly shorter version would be:
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => {
/*
write your code here referencing the `input` variable
as the actual input received
*/
console.log(result);// result would be the output expected
});
Thank you so much, Randell. The problem is that I have not yet studied NodeJS, so I have some studying to do before tackling this one. I appreciate this response and am going to save it for my notes (: