Bird
0
0

Identify the error in this PowerShell script:

medium📝 Debug Q14 of 15
PowerShell - Variables and Data Types
Identify the error in this PowerShell script:
$number = 10
$number = $number + 5
Write-Output number
ACannot add numbers in PowerShell
BVariable <code>$number</code> not declared
CMissing <code>$</code> before 'number' in Write-Output
DWrite-Output cannot print variables
Step-by-Step Solution
Solution:
  1. Step 1: Check variable usage in Write-Output

    The script tries to print 'number' without $, so it prints the word literally.
  2. Step 2: Correct usage of variable in output

    To print the variable value, it should be Write-Output $number.
  3. Final Answer:

    Missing $ before 'number' in Write-Output -> Option C
  4. Quick Check:

    Variables need $ to be recognized [OK]
Quick Trick: Always use $ before variable names when printing [OK]
Common Mistakes:
  • Forgetting $ before variable in output
  • Thinking variables need declaration keyword
  • Assuming Write-Output can't print variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes