Coder Social home page Coder Social logo

mern-ancestor-offspring-09's Introduction

EXPERIMENT-09

Finding ancestor and offspring

Aim:

The aim of the given code is to create a function that takes a number and a character representing the gender ("m" for male, "f" for female) and returns the name of an ancestor (m/f) or descendant (m/f) based on the input values.

Algorithm:

1. Create a function named check that takes two parameters: num (the 
number representing the generation) and gen (the character 
representing the gender).
2. Inside the function, check the value of gen to determine whether it 
represents a male or female.
3. If gen is equal to 'f', execute the following steps:
• Use a switch statement to check the value of num:
• If num is -1, print "Mother".
• If num is -2, print "Grand Mother".
• If num is -3, print "Great Grand Mother".
• If num is 0, print "ME".
• If num is 1, print "Daughter".
• If num is 2, print "Grand Daughter".
• If num is 3, print "Great Grand Daughter".
4. If gen is equal to 'm', execute the following steps:
• Use a switch statement to check the value of num:
• If num is -1, print "Father".
• If num is -2, print "Grand Father".
• If num is -3, print "Great Grand Father".
• If num is 0, print "ME".
• If num is 1, print "Son".
• If num is 2, print "Grand Son".
• If num is 3, print "Great Grand Son".
5. Close the switch statement and the if-else statement.
6. Call the check function with the arguments 1 and 'f'.

Programm:

function check(num,gen)
{
 if(gen=='f')
 {
 switch(num)
 {
 case -1:
 console.log("Mother")
 break
 case -2:
 console.log("Grand Mother")
 break
 case -3:
 console.log("Great Grand Mother")
 break
 case 0:
 console.log("ME")
 break
 
 case 1:
 console.log("Daughter")
 break
 case 2:
 console.log("Grand Daughter")
 break
 
 case 3:
 console.log("Great Grand Daughter")
 break
 }
 }
 else if(gen == 'm')
 {
 switch(num)
 {
 case -1:
 console.log("Father")
 break
 case -2:
 console.log("Grand Father")
 break
 case -3:
 console.log("Great Grand Father")
 break
 case 0:
 console.log("ME")
 break
 
 case 1:
 console.log("Son")
 break
 case 2:
 console.log("Grand Son")
 break
 
 case 3:
 console.log("Great Grand Son")
 break
}
}
}
check.call(this,1,'f')

Output:

image

Results:

The output of the given code, when calling the check function with 1 as num and 'f' as gen, will be "Daughter".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.