Bird
0
0

You want to organize a script that calculates the area of different shapes. Which approach best uses functions to keep the script clean and reusable?

hard📝 Application Q15 of 15
PowerShell - Functions
You want to organize a script that calculates the area of different shapes. Which approach best uses functions to keep the script clean and reusable?
AWrite all calculations in one long script without functions
BCreate separate functions like Get-AreaCircle, Get-AreaSquare, each taking parameters and returning results
CUse functions but hardcode values inside them without parameters
DWrite functions that only print results without returning values
Step-by-Step Solution
Solution:
  1. Step 1: Identify best practice for organizing calculations

    Separate functions for each shape with parameters allow reuse and clarity.
  2. Step 2: Evaluate other options for drawbacks

    One long script is hard to maintain; hardcoded values reduce flexibility; printing without returning limits reuse.
  3. Final Answer:

    Create separate functions like Get-AreaCircle, Get-AreaSquare, each taking parameters and returning results -> Option B
  4. Quick Check:

    Functions with parameters and return values = Create separate functions like Get-AreaCircle, Get-AreaSquare, each taking parameters and returning results [OK]
Quick Trick: Use functions with parameters for reusable calculations [OK]
Common Mistakes:
  • Putting all code in one script block
  • Hardcoding values inside functions
  • Not returning values from functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes