Challenge - 5 Problems
Master of Variables and Control Flow in dbt
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of variable assignment and if condition in dbt
What is the output of the following dbt Jinja code snippet when run inside a model?
dbt
{% set x = 5 %}
{% if x > 3 %}
{{ x * 2 }}
{% else %}
{{ x + 2 }}
{% endif %}Attempts:
2 left
💡 Hint
Check the value of x and the condition in the if statement.
✗ Incorrect
The variable x is set to 5. Since 5 is greater than 3, the if block runs, outputting 5 * 2 = 10.
❓ data_output
intermediate2:00remaining
Result of loop with variable increment in dbt
What list will be output by this dbt Jinja code?
dbt
{% set result = [] %}
{% set counter = 0 %}
{% for i in range(3) %}
{% set counter = counter + i %}
{% do result.append(counter) %}
{% endfor %}
{{ result }}Attempts:
2 left
💡 Hint
Remember that counter starts at 0 and increments by i each loop.
✗ Incorrect
Loop runs with i=0,1,2. counter updates: 0+0=0, 0+1=1, 1+2=3. Result list collects these values.
🔧 Debug
advanced2:00remaining
Identify the error in variable scope within dbt Jinja
Why does the following dbt code raise an error or produce unexpected output?
dbt
{% for i in range(2) %}
{% set val = i * 2 %}
{% endfor %}
{{ val }}Attempts:
2 left
💡 Hint
Consider variable scope inside and outside loops in Jinja.
✗ Incorrect
In dbt Jinja, variables set inside loops are local to the loop block and not accessible outside, so val is undefined after the loop.
🧠 Conceptual
advanced2:00remaining
Understanding control flow with nested if-else in dbt
Given the variable 'score' set to 75, what will this dbt Jinja code output?
dbt
{% set score = 75 %}
{% if score >= 90 %}
Excellent
{% elif score >= 70 %}
Good
{% else %}
Needs Improvement
{% endif %}Attempts:
2 left
💡 Hint
Check the conditions in order and which one matches 75.
✗ Incorrect
75 is not >= 90 but is >= 70, so the elif block runs, outputting 'Good'.
🚀 Application
expert3:00remaining
Predict the output of complex variable manipulation and control flow in dbt
What is the final output of this dbt Jinja code snippet?
dbt
{% set data = [1, 2, 3, 4] %}
{% set total = 0 %}
{% for num in data %}
{% if num % 2 == 0 %}
{% set total = total + num * 2 %}
{% else %}
{% set total = total + num %}
{% endif %}
{% endfor %}
{{ total }}Attempts:
2 left
💡 Hint
Calculate total step by step, doubling even numbers before adding.
✗ Incorrect
Loop over [1,2,3,4]:
1 (odd) add 1 → total=1
2 (even) add 4 → total=5
3 (odd) add 3 → total=8
4 (even) add 8 → total=16
Final total is 16.