[{"id":"kotlinbeginner-001","courseId":"kotlin-beginner","domain":"basics-and-types","topic":"when evaluation order","prompt":"A when with a subject checks one value against several branch conditions and ends with an else branch. Put these steps in the order the when runs them.","hint":"Think about what the when must have before it can test any branch, and which branch it tests first.","explain":"A when with a subject tests one value against its branch conditions, one condition at a time. Think about what must exist before any test can run, and about where the fallback branch fits among the tests.","source":"https://kotlinlang.org/docs/control-flow.html","interaction":{"type":"sort","items":[{"text":"Evaluate the subject of the when once","why":"when computes its argument before it compares that value with any branch."},{"text":"Compare the subject with the first branch condition","why":"Branch conditions are compared in the order they are written, starting from the top."},{"text":"If that condition fails, compare with the next one","why":"The comparisons continue down the list until one branch condition is satisfied."},{"text":"If no condition matched, run the else branch","why":"The else branch is evaluated only when none of the other branch conditions are satisfied, so it comes last."}]},"options":[],"answer":"o:abcd","explanation":"A when with a subject evaluates its argument, compares it with the branch conditions in written order until one is satisfied, and evaluates else only when none was.","concept":"A when with a subject evaluates its argument, compares it with the branch conditions in written order until one is satisfied, and evaluates else only when none was.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["A when with a subject checks its branch conditions in the order they are written."]},{"id":"kotlinbeginner-002","courseId":"kotlin-beginner","domain":"basics-and-types","topic":"String templates","prompt":"A teammate runs this code. What line does the program print?","hint":"Look at what the dollar sign does inside the quotes.","explain":"Double-quoted strings can hold placeholders. A dollar sign before a name, or a dollar sign and braces around an expression, marks a spot that gets filled in when the text is made.","source":"https://kotlinlang.org/docs/strings.html","interaction":{"type":"single"},"options":[{"id":"a","text":"Items: 4","why":"A dollar sign before a name inserts that variable's value into the text."},{"id":"b","text":"Items: $count","whyNot":"A $ followed by a name is a template, so it is replaced, not kept as text."},{"id":"c","text":"Items: count","whyNot":"The $ is not dropped; it marks the name as a template whose value is inserted."},{"id":"d","text":"A compile error, because a template can't hold an Int","whyNot":"Nothing in a template limits which variables can be inserted, and this one is a plain number."}],"answer":"a","explanation":"Inside a double-quoted string, $name inserts the value of that variable, and ${expression} inserts the value of an expression.","concept":"Inside a double-quoted string, $name inserts the value of that variable, and ${expression} inserts the value of an expression.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"val count = 4\nval label = \"Items: $count\"\nprintln(label)","takeaways":["Inside double quotes, $name inserts a variable's value into the text."]},{"id":"kotlinbeginner-003","courseId":"kotlin-beginner","domain":"basics-and-types","topic":"Multiline strings","prompt":"Inside a triple-quoted string, the two characters \\n are converted into a line break, just as they are in a normal string.","hint":"Compare the quote style with a regular string literal.","explain":"Backslash codes such as a tab or a newline are special in some string literals. Which quote style a literal uses decides which rules apply to the characters inside it.","source":"https://kotlinlang.org/docs/strings.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"That holds for normal double-quoted strings, but triple quotes treat backslashes as plain text."},{"id":"b","text":"False","why":"Multiline strings don't support escape sequences, so \\n stays as a backslash followed by n."}],"answer":"b","explanation":"Multiline strings in triple quotes don't support escape sequences; backslashes are regular text. Double-quoted strings do support \\n and \\t.","concept":"Multiline strings in triple quotes don't support escape sequences; backslashes are regular text. Double-quoted strings do support \\n and \\t.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"val text = \"\"\"Line one\\nLine two\"\"\"\nprintln(text)","takeaways":["Triple-quoted strings treat backslash codes as plain text."]},{"id":"kotlinbeginner-004","courseId":"kotlin-beginner","domain":"basics-and-types","topic":"Nullable types","prompt":"Given the code below, what happens when the compiler reaches the third line?","hint":"Look at the question mark in the declared type.","explain":"Kotlin separates types that can hold null from types that cannot. A ? after a declared type marks the nullable kind, and the compiler checks member access against that declared type.","source":"https://kotlinlang.org/docs/null-safety.html","interaction":{"type":"single"},"options":[{"id":"a","text":"The compiler reports an error, because b's type allows null","why":"The compiler rejects direct member access on a nullable type, since b may hold null."},{"id":"b","text":"It compiles and sets l to 3, since b was first set to \"abc\"","whyNot":"Kotlin checks the declared type of b, not a value it held earlier."},{"id":"c","text":"It compiles, and l becomes null whenever b is null","whyNot":"Direct access doesn't turn into a safe call; you must write ?. yourself."},{"id":"d","text":"It compiles, and the error appears only if b is null at run time","whyNot":"The check happens at compile time, before the program runs."}],"answer":"a","explanation":"A type written with ? (like String?) can hold null, and the compiler rejects direct member access such as b.length on it; a safe call or null check is needed.","concept":"A type written with ? (like String?) can hold null, and the compiler rejects direct member access such as b.length on it; a safe call or null check is needed.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"var b: String? = \"abc\"\nb = null\nval l = b.length","takeaways":["String? can hold null; String cannot, so direct member access fails."]},{"id":"kotlinbeginner-005","courseId":"kotlin-beginner","domain":"basics-and-types","topic":"Safe call operator","prompt":"A variable is declared as val a: String? = null, and the code runs val n = a?.length. Which TWO statements about n are true?","hint":"Think about what happens instead of an exception.","explain":"Some operators let you call members on a value that might be null without crashing. Think about what the result's type has to allow when the call is skipped.","source":"https://kotlinlang.org/docs/null-safety.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The type of n is Int?, so it can hold null.","why":"The result of a call that may be skipped is nullable, so the type is Int?."},{"id":"b","text":"n is null, and no NullPointerException is thrown.","why":"Instead of throwing an NPE, the ?. operator simply returns null when the receiver is null."},{"id":"c","text":"The code throws a NullPointerException on this line.","whyNot":"That describes a!!.length; ?. returns null rather than throwing."},{"id":"d","text":"The type of n is Int, with null replaced by 0.","whyNot":"No replacement with 0 happens; the result is nullable, so the type is Int?."},{"id":"e","text":"?. works only on var variables, not on val.","whyNot":"?. works with both var and val variables."},{"id":"f","text":"a?.length behaves the same as a!!.length here.","whyNot":"!! throws an NPE on null, while ?. returns null, so the two differ here."}],"answer":"ab","explanation":"The ?. operator returns null instead of throwing an NPE when the receiver is null, so a?.length has type Int?. It works with both var and val.","concept":"The ?. operator returns null instead of throwing an NPE when the receiver is null, so a?.length has type Int?. It works with both var and val.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"val a: String? = null\nval n = a?.length\nprintln(n)","takeaways":["a?.member gives a nullable result; a!!.member throws if a is null."]}]