Bird
0
0

You want to store a user's age and then increase it by 1. Which script correctly updates the variable?

hard📝 Application Q8 of 15
PowerShell - Variables and Data Types
You want to store a user's age and then increase it by 1. Which script correctly updates the variable?
A$age = 30 $age = $age + 1 Write-Output $age
B$age = 30 $age + 1 Write-Output $age
C$age = 30 Add 1 to $age Write-Output $age
D$age = 30 $age += Write-Output $age
Step-by-Step Solution
Solution:
  1. Step 1: Check how variable is updated

    $age = 30 $age = $age + 1 Write-Output $age correctly adds 1 and assigns back to $age.
  2. Step 2: Verify output command

    Write-Output prints updated $age value, which will be 31.
  3. Final Answer:

    $age = 30 $age = $age + 1 Write-Output $age -> Option A
  4. Quick Check:

    Proper variable update uses assignment after addition [OK]
Quick Trick: Add and assign back to variable to update value [OK]
Common Mistakes:
  • Adding without assignment
  • Using invalid syntax like 'Add 1 to $age'
  • Incomplete operators like '+=' without value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes