[{"id":"gobeginner-001","courseId":"go-beginner","domain":"types-values","topic":"Short variable declarations","prompt":"In one function, `count := 1` runs first. A later line in the same block reads `count, err := parse(s)`, where parse returns an int and an error, and err is a new name. What does that line do to count?","hint":"Check whether the name on the left gets a fresh variable or keeps the old one.","explain":"The := operator can mix new and existing names on its left side. Think about whether a name already declared in the same block gets a fresh variable or keeps the one it has.","source":"https://go.dev/ref/spec#Short_variable_declarations","interaction":{"type":"single"},"options":[{"id":"a","text":"It assigns the new parsed value to the existing count","why":"Redeclaration creates no new variable. With at least one new name on the left, := assigns to the original count."},{"id":"b","text":"It declares a second count that hides the first","whyNot":"Hiding needs a new block. In the same block, := reuses the existing variable rather than creating another."},{"id":"c","text":"It is a compile error, because := cannot touch an existing name","whyNot":"A mix of old and new names is allowed, as long as at least one name on the left is new."},{"id":"d","text":"It resets count to zero, then assigns the new value","whyNot":"Nothing resets the variable; the existing value is simply replaced by the value being assigned."}],"answer":"a","explanation":"A short variable declaration may redeclare variables from the same block when at least one left-side name is new; redeclaration assigns to the original and creates no variable.","concept":"A short variable declaration may redeclare variables from the same block when at least one left-side name is new; redeclaration assigns to the original and creates no variable.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"count := 1\ncount, err := parse(s)","takeaways":["Inside one block, := reuses an existing name when at least one name on its left is new."]},{"id":"gobeginner-002","courseId":"go-beginner","domain":"types-values","topic":"Zero values","prompt":"Judge this statement: after `var names []string` with no assignment, `names` holds nil, which is the zero value for a slice.","hint":"Think about what an uninitialized slice holds, compared with a slice that has been made empty.","explain":"Variables declared without an initial value get the zero value of their type. A slice has its own zero value, and it is a different thing from a slice that was created with no elements.","source":"https://go.dev/ref/spec#Variable_declarations","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"The spec says the value of an uninitialized slice is nil, the zero value for slice types."},{"id":"b","text":"False","whyNot":"An uninitialized slice is nil, not a non-nil empty slice. Its length is still 0, and nil is what it holds."}],"answer":"a","explanation":"The zero value of a slice type is nil, so an uninitialized slice holds nil rather than an empty allocated slice.","concept":"The zero value of a slice type is nil, so an uninitialized slice holds nil rather than an empty allocated slice.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"var names []string","takeaways":["A declared slice with no value holds nil, the zero value for slice types."]},{"id":"gobeginner-003","courseId":"go-beginner","domain":"types-values","topic":"Constant declarations","prompt":"A teammate shares this const block that uses iota. Put the four constants in order, from smallest value to largest value.","hint":"Work out the iota value on each line, then evaluate that line's expression.","explain":"Inside the const block, iota counts lines from zero and rises by one on each line. An expression can read the current iota, so one formula can give different values on different lines.","source":"https://go.dev/ref/spec#Constant_declarations","interaction":{"type":"sort","items":[{"text":"a","why":"Smallest: iota is 0 on its line, so 1 << 0 is 1."},{"text":"b","why":"iota is 1 on its line, so 1 << 1 is 2."},{"text":"c","why":"A fixed 3, which falls after b's 2 and before d's 8."},{"text":"d","why":"iota is 3 on its line, so 1 << 3 is 8, the largest."}]},"options":[],"answer":"o:abcd","explanation":"iota is the index of the ConstSpec within its const block, starting at zero, so each line can compute a value from its own position.","concept":"iota is the index of the ConstSpec within its const block, starting at zero, so each line can compute a value from its own position.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"const (\n    a = 1 << iota\n    b = 1 << iota\n    c = 3\n    d = 1 << iota\n)","takeaways":["iota counts ConstSpec lines from zero, so 1 << iota doubles on each line."]},{"id":"gobeginner-004","courseId":"go-beginner","domain":"types-values","topic":"Integer division","prompt":"A program runs `total := -7 / 2`, where both -7 and 2 are int values. What value does total hold?","hint":"Consider what happens to the fractional part when both operands are integers.","explain":"Dividing two int values gives a whole-number result. The spec defines exactly how the fraction is dropped, and the sign of the dividend affects the direction, so reason about that.","source":"https://go.dev/ref/spec#Integer_operators","interaction":{"type":"single"},"options":[{"id":"a","text":"-3","why":"Integer division truncates toward zero. The exact quotient -3.5 drops its fraction, moving the result toward zero to -3."},{"id":"b","text":"-4","whyNot":"That is floor division, which rounds toward negative infinity. Go's / truncates toward zero instead."},{"id":"c","text":"-3.5","whyNot":"Both operands are int, so the result is an integer and no fractional part is kept."},{"id":"d","text":"3","whyNot":"The sign is not dropped. A negative dividend gives a negative quotient, so the result is negative."}],"answer":"a","explanation":"Integer division x / y truncates toward zero, so -7 / 2 is -3, and the remainder -7 % 2 is -1.","concept":"Integer division x / y truncates toward zero, so -7 / 2 is -3, and the remainder -7 % 2 is -1.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"total := -7 / 2","takeaways":["Integer / truncates toward zero, so a negative quotient rounds up toward zero."]},{"id":"gobeginner-005","courseId":"go-beginner","domain":"types-values","topic":"String immutability","prompt":"Judge this statement: after `s := \"Jello\"`, the line `s[0] = 'J'` changes the first byte of s in place.","hint":"Think about what kind of value a string is once it has been created.","explain":"A Go string is a sequence of bytes. Indexing it gives you a byte, and the spec states what can and cannot happen to a string's contents once the string exists.","source":"https://go.dev/ref/spec#String_types","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Indexing looks like it gives a writable slot, but the contents of a string cannot be changed after it is created."},{"id":"b","text":"False","why":"Strings are immutable. s[0] can be read, but assigning to it is not allowed, so you build a new string instead."}],"answer":"b","explanation":"Strings are immutable: once created, their contents cannot be changed, and taking the address of a byte with &s[i] is invalid.","concept":"Strings are immutable: once created, their contents cannot be changed, and taking the address of a byte with &s[i] is invalid.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"s := \"Jello\"\ns[0] = 'J'","takeaways":["A string cannot be changed in place; build a new string from the parts you need."]}]