Bird
0
0

Identify the error in this PowerShell code:

medium📝 Debug Q6 of 15
PowerShell - Working with Objects
Identify the error in this PowerShell code:
$num = 5
$num.ToUpper()
AToUpper() should be called as ToUpper without parentheses
BVariable $num is not defined
CToUpper() method does not exist for integers
DMissing parentheses after $num
Step-by-Step Solution
Solution:
  1. Step 1: Check variable type

    $num is an integer (5), not a string.
  2. Step 2: Verify method availability

    ToUpper() is a string method, not valid for integers.
  3. Final Answer:

    ToUpper() method does not exist for integers -> Option C
  4. Quick Check:

    ToUpper() on int = D [OK]
Quick Trick: Only strings have ToUpper() method [OK]
Common Mistakes:
  • Assuming all objects have ToUpper()
  • Ignoring variable type
  • Syntax errors unrelated to method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes