wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
$count = 21; if ($count = 21) {{}} | $count = 21; if ($count == 21) {{}} | Use ==. | PHP |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
if num > 42
puts 'hello' | if num > 42
puts 'hello'
end | Add 'end'. | Ruby |
List(25,15,30) | List(25,15,30) | Correct. | Scala |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
local foo = 52 | local foo = 52 | Correct. | Lua |
jwt.sign({{id:99}}, 'secret'); | jwt.sign({{id:99}}, 'secret', {{expiresIn:'15m'}}); | Add expiration. | Node.js |
{{"id":"value" "title":49}} | {{"id":"value", "title":49}} | Add comma. | JSON |
var x int | var x int | Correct. | Go |
System.out.println('hello') | System.out.println('hello'); | Add semicolon. | Java |
process | process() | Add parentheses. | Kotlin |
echo value data | echo 'value data' | Quote to prevent splitting. | Shell |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
item = message | item = 'message' | Quote strings. | Python |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
data == '79' | data === 79 | Use strict equality. | JavaScript |
let count = 76; | let count = 76; | Correct. | JavaScript |
try {{ throw 'result'; }} catch(e) {{}} | try {{ throw new Error('result'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
<br></br> | <br> | Self-closing. | HTML |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
int x = 'hello'; | String x = 'hello'; | Type mismatch. | Dart |
[27, 1, 39 | [27, 1, 39] | Close bracket. | Ruby |
Write-Host 'result' | Write-Host 'result' | Correct. | PowerShell |
while item > 44
item -= 1 | while item > 44:
item -= 1 | Colon missing after while. | Python |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
if (foo = 91) {{}} | if (foo == 91) {{}} | Use ==. | Kotlin |
if count = 10 | if count == 10 | Use ==. | Go |
$arr[12] | if ($arr.Count -gt 12) {{ $arr[12] }} | Check bounds. | PowerShell |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
if (c) console.log('yes') else console.log('no') | if (c) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
const obj:Person = {{name:'output'}}; | const obj:Person = {{name:'output', age:74}}; | Add missing property. | TypeScript |
'hello' + 96 | 'hello' + str(96) | Can't add int to string. | Python |
h1 {{ font-size:42px color:red; }} | h1 {{ font-size:42px; color:red; }} | Add semicolon. | CSS |
let y: i32 = "data"; | let y: &str = "data"; | Type mismatch. | Rust |
function foo(y:string){{return y;}} foo(73); | function foo(y:string){{return y;}} foo('value'); | Pass correct type. | TypeScript |
String num = 'message'; | String num = "message"; | Double quotes. | Java |
y > 14 & a < 75 | y > 14 and a < 75 | Use 'and' not '&'. | Python |
let a = 12; let a = 74; | let a = 12; a = 74; | Duplicate declaration. | JavaScript |
var x = 47; | var x = 47; | Correct. | Dart |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
var index int = 'output' | var index string = 'output' | Type mismatch. | Go |
def baz
puts 'data'
end | def baz
puts 'data'
end | Correct. | Ruby |
function baz(): void {{ return 35; }} | function baz(): number {{ return 35; }} | Return type mismatch. | TypeScript |
list[53] | if (list.indices.contains(53)) list[53] | Check index. | Kotlin |
assert a > 38 | assert a > 38 | Correct. | Python |
let str1 = String::from("hello"); let str2 = str1; println!("{{}}", str1); | let str1 = String::from("hello"); let str2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
echo 'hello' | echo 'hello'; | Add semicolon. | PHP |
["data", 42] | ["data", 42] | Correct. | JSON |
def bar():
print('result') | def bar():
print('result') | Indent function body. | Python |
int[] items = new int[18];
items[18] = 5; | int[] items = new int[18];
if (18 < items.length) items[18] = 5; | Check bounds. | Java |
if bar = 82 {{}} | if bar == 82 {{}} | Use ==. | Swift |
DELETE FROM products WHERE id=8 | DELETE FROM products WHERE id=8; | Add semicolon. | SQL |
val result: Int = 'world' | val result: String = 'world' | Fix type. | Kotlin |
Product.save(); | Product.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
#main {{ color: green; }} | #main {{ color: green; }} | Correct. | CSS |
<table><tr><td>data<td>hello</tr></table> | <table><tr><td>data</td><td>hello</td></tr></table> | Close td. | HTML |
yield bar | yield bar | Correct yield. | Python |
fn bar() -> i32 {{ 64 }} | fn bar() -> i32 {{ 64 }} | Correct. | Rust |
jwt.sign({{id:39}}, 'key'); | jwt.sign({{id:39}}, 'key', {{expiresIn:'30m'}}); | Add expiration. | Node.js |
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(82); | const http = require('http'); http.createServer((req,res) => res.end('data')).listen(82); | Correct. | Node.js |
class Item
def method
end
end | class Item
def method
end
end | Correct. | Ruby |
<person age=37> | <person age="37"> | Quote attribute. | XML |
disp('test') | disp('test') | Correct. | MATLAB |
{{'status':67, 'status' 87}} | {{'status':67, 'status':87}} | Colon missing. | Python |
print 'data' | print 'data'; | Add semicolon. | Perl |
x := 67 | x := 67 | Correct. | Go |
<div><p>result</div></p> | <div><p>result</p></div> | Nest properly. | HTML |
let x = 'info' | let x = "info" | Double quotes. | Swift |
match index {{ 1 => {{}} }} | match index {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
class = 'value' | class_name = 'value' | 'class' is a keyword. | Python |
'19' + 16 | 19 + 16 | Avoid string coercion. | JavaScript |
function process() {{
return
{{key:'data'}}
}} | function process() {{
return {{key:'data'}};
}} | Return object on same line. | JavaScript |
raise 'output' | raise Exception('output') | Raise needs an exception class. | Python |
println('info') | println("info") | Double quotes. | Scala |
def baz(c):
return c + 1 | def baz(c):
return c + 1 | Correct. | Python |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
cin >> data; | int data;
cin >> data; | Declare variable. | C++ |
WHERE email = '82' | WHERE email = 82 | Don't quote integer. | SQL |
<div color=red> | <div style='color:red;'> | Use style attribute. | CSS |
if foo > 52
print('message') | if foo > 52:
print('message') | Colon missing after if. | Python |
{ "name": "world" } | { "name": "world" } | Correct. | JSON |
<input type='text' value='test'> | <input type='text' value='test' name='age'> | Add name attribute. | HTML |
if (x = 32) | if (x == 32) | Use ==. | R |
<user name='hello'/> | <user name="hello"/> | Double quotes. | XML |
function test(x)
print(x)
end | function test(x)
print(x)
end | Correct. | Lua |
SELECT COUNT(*) FROM users | SELECT COUNT(*) FROM users; | Missing semicolon. | SQL |
if data = 40: | if data == 40: | Use == for comparison. | Python |
if ($num = 10) {{}} | if ($num -eq 10) {{}} | Use -eq. | PowerShell |
with open('data.txt') as fp:
data = fp.read() | with open('data.txt') as fp:
data = fp.read() | Correct. | Python |
else
print('value') | else:
print('value') | Colon after else. | Python |
if a > 74
puts 'data' | if a > 74
puts 'data'
end | Add 'end'. | Ruby |
if (data = 91) | if (data == 91) | Use ==. | Scala |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
if [ $temp = 61 ]; then | if [ "$temp" = 61 ]; then | Quote variable. | Shell |
object Item {{ def main(args: Array[String]) = println("hello") }} | object Item {{ def main(args: Array[String]): Unit = println("hello") }} | Add return type Unit. | Scala |
UPDATE products SET age='data' WHERE email=47 | UPDATE products SET age='data' WHERE email=47; | Add semicolon. | SQL |
$data[93] = 5; | if (isset($data[93])) $data[93] = 5; | Check existence. | PHP |
if num = 81 | if num == 81 | Use ==. | MATLAB |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.