Sort by

recency

|

1896 Discussions

|

  • + 0 comments

    JavaScript solution:

    function Person(initialAge){
        if (initialAge < 0) {
            console.log("Age is not valid, setting age to 0.");
            this.age = 0;
        } else {
            this.age = initialAge;
        }
        
      this.amIOld=function(){
       if (this.age < 13) {
        console.log("You are young.");
       } else if (this.age >= 13 && this.age < 18) {
        console.log("You are a teenager."); 
       } else {
        console.log("You are old.");
       };
       
      };
       this.yearPasses=function(){
              this.age += 1;
       };
    }
    
  • + 0 comments

    4th exercise isnt available in C and idk any other language help

  • + 1 comment

    Python3 solution: On the same point as per my earlier message, I referred to the solution present in the Editorial section as well and tried it. It is still failing with the initial test case where initalAge is -1. Can anyone please advise on what is wrong in the code?

    class Person: def init(self,initialAge): if (initialAge < 0): print("Age is not valid, setting age to 0") self.age = 0 else: self.age = initialAge

    def amIOld(self):
        if self.age >= 18:
            print("You are old.")
        elif self.age >= 13:
            print("You are a teenager.")
        else:
            print("You are young.")
    
    def yearPasses(self):
        self.age += 1
    
  • + 0 comments

    Python3 solution: Is there something wrong with my code? The test cases are failing. I checked the solutions from the leaderboard (even though I will not get the points now :-)) and its similar to that. I am confused here. class Person: def init(self,initialAge): if initialAge < 0: self.age = 0 print("Age is not valid, setting age to 0") else: self.age = initialAge def amIOld(self): if self.age < 13: print("You are young.") elif 13 <= self.age < 18: print("You are a teenager.") else: print("You are old.") def yearPasses(self): self.age += 1

  • + 0 comments

    I think my solution it's ok, a blank line is being printed at the end of execution but I'm not allowed to modify that code and because of that I think the outcome is a "wrong" answer, please let me know if you see something wrong with my solution

    process.stdin.resume();
    process.stdin.setEncoding('ascii');
    
    var input_stdin = "";
    var input_stdin_array = "";
    var input_currentline = 0;
    
    process.stdin.on('data', function (data) {
        input_stdin += data;
    });
    
    process.stdin.on('end', function () {
        input_stdin_array = input_stdin.split("\n");
        main();    
    });
    
    function readLine() {
        return input_stdin_array[input_currentline++];
    }
    function Person(initialAge) {
      this.age = initialAge;
      if (this.age < 0) {
          this.age = 0;
          console.log("Age is not valid, setting age to 0.");
      }
        // Add some more code to run some checks on initialAge
        this.amIOld=function(){
                // Do some computations in here and print out the correct statement to the console
                if (this.age < 13) {
                    console.log("You are young.");
                } else {
                    if ( this.age < 18) {
                        console.log("You are teenager.");
                    } else {
                        console.log("You are old.");
                    }
                }
        };
       this.yearPasses=function(){
              // Increment the age of the person in here
              this.age++;
       };
    }
    
    
    function main() {
    
    var T=parseInt(readLine());
    for(i=0;i<T;i++){
        var age=parseInt(readLine());
        var p=new Person(age);
        p.amIOld();
        for(j=0;j<3;j++){
            p.yearPasses();
            
        }
        p.amIOld();
        console.log("");   
        }
    }