wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
let item = 74; let item = 45; | let item = 74; item = 45; | Duplicate declaration. | JavaScript |
if (a = 21) | if (a == 21) | Use ==. | R |
with open('log.txt') as fp:
data = fp.read() | with open('log.txt') as fp:
data = fp.read() | Correct. | Python |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
class = 'world' | class_name = 'world' | 'class' is a keyword. | Python |
h1 {{ font-size:48px color:green; }} | h1 {{ font-size:48px; color:green; }} | Add semicolon. | CSS |
let b: number = 'value'; | let b: string = 'value'; | Fix type. | TypeScript |
<ul><li>world<li>data</ul> | <ul><li>world</li><li>data</li></ul> | Close li. | HTML |
INSERT INTO products VALUES ('data',65) | INSERT INTO products (name, status) VALUES ('data',65); | Specify columns. | SQL |
x := 69 | x := 69 | Correct. | Go |
echo output test | echo 'output test' | Quote to prevent splitting. | Shell |
if (item) console.log('yes') else console.log('no') | if (item) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
x = 31 | x=31 | No spaces. | Shell |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(10); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(10, () => console.log('listening')); | Add callback. | Node.js |
$bar = 83; if ($bar = 83) {{}} | $bar = 83; if ($bar == 83) {{}} | Use ==. | PHP |
name: value
age: 29 | name: value
age: 29 | Correct. | YAML |
class Person {{ int count; }}; | class Person {{ public: int count; }}; | Make public. | C++ |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
let mut foo=80; let ref1=&mut foo; let r2=&mut foo; | let mut foo=80; {{ let ref1=&mut foo; }} let r2=&mut foo; | Only one mutable borrow. | Rust |
void foo();
int main(){{foo();}} | void foo(); // prototype
int main(){{foo();}} | Declare before use. | C++ |
let a: number | null = null; a.toFixed(12); | let a: number | null = null; if(a!==null) a.toFixed(12); | Null check. | TypeScript |
String name = 'info'; | String name = 'info'; | Correct. | Dart |
<div color=#fff> | <div style='color:#fff;'> | Use style attribute. | CSS |
print('value') | print('value') | Correct. | R |
let c: i32 = "output"; | let c: &str = "output"; | Type mismatch. | Rust |
const data = 61; data = 48; | let data = 61; data = 48; | Cannot reassign const. | JavaScript |
$data[51] | if ($data.Count -gt 51) {{ $data[51] }} | Check bounds. | PowerShell |
void main() {{ print('world') }} | void main() {{ print('world'); }} | Add semicolon. | Dart |
data[41] | if (length(data) >= 41) data[41] | Check length. | R |
arr(100) | if length(arr) >= 100, arr(100), end | Check length. | MATLAB |
UPDATE orders SET id='test' WHERE role=13 | UPDATE orders SET id='test' WHERE role=13; | Add semicolon. | SQL |
cin >> data
cout << data; | cin >> data;
cout << data; | Add semicolon. | C++ |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
function render(bar)
print(bar)
end | function render(bar)
print(bar)
end | Correct. | Lua |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
{{"age":"hello" "age":57}} | {{"age":"hello", "age":57}} | Add comma. | JSON |
val a = 67; a = 87 | var a = 67; a = 87 | Use var for reassignment. | Scala |
if bar = 76 then
print('world')
end | if bar == 76 then
print('world')
end | Use ==. | Lua |
let temp: Int = 'info' | let temp: String = 'info' | Fix type. | Swift |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
<p>world <b>hello</p></b> | <p>world <b>hello</b></p> | Nest properly. | HTML |
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(23); | const http = require('http'); http.createServer((req,res) => res.end('info')).listen(23); | Correct. | Node.js |
if (count = 41) {{}} | if (count == 41) {{}} | Use ==. | Kotlin |
76z = 10 | z76 = 10 | Variable cannot start with digit. | Python |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
class Product {{ int bar; }}
obj.bar=5; | class Product {{ public int bar; }}
obj.bar=5; | Make field public. | Java |
if (foo = 50) | if (foo == 50) | Use ==. | C++ |
def compute(a):
return a + 1 | def compute(a):
return a + 1 | Correct. | Python |
if (result = 37) | if (result == 37) | Use ==. | R |
{{'id':1, 'name' 28}} | {{'id':1, 'name':28}} | Colon missing. | Python |
println('result') | println("result") | Double quotes. | Scala |
[56, 1, 59 | [56, 1, 59] | Close bracket. | Ruby |
let text1 = String::from("output"); let str2 = text1; println!("{{}}", text1); | let text1 = String::from("output"); let str2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
let bar: number = 'value'; | let bar: string = 'value'; | Fix type. | TypeScript |
function baz() {{
return
{{key:'message'}}
}} | function baz() {{
return {{key:'message'}};
}} | Return object on same line. | JavaScript |
<hr></hr> | <hr> | Self-closing. | HTML |
[x*x for x in list if x > 13] | [x*x for x in list if x > 13] | Correct list comprehension. | Python |
{{'status':'world'}} | {{"status":"world"}} | Use double quotes. | JSON |
Order.save(); | Order.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
{ "name": "world" } | { "name": "world" } | Correct. | JSON |
yield c | yield c | Correct yield. | Python |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
// comment | /* comment */ | Use /* */. | CSS |
fmt.Println 'hello' | fmt.Println('hello') | Missing parentheses. | Go |
foo = hello | foo = 'hello' | Quote strings. | Python |
DELETE FROM products WHERE name=32 | DELETE FROM products WHERE name=32; | Add semicolon. | SQL |
function foo(): void {{ return 92; }} | function foo(): number {{ return 92; }} | Return type mismatch. | TypeScript |
function process(result:string){{return result;}} process(31); | function process(result:string){{return result;}} process('info'); | Pass correct type. | TypeScript |
if (b = 23) {} | if (b == 23) {} | Use ==. | Dart |
def bar
puts 'data'
end | def bar
puts 'data'
end | Correct. | Ruby |
test | test() | Add parentheses. | Kotlin |
assert a > 9 | assert a > 9 | Correct. | Python |
if ($result = 76) | if ($result == 76) | Use ==. | Perl |
jwt.sign({{id:65}}, 'key'); | jwt.sign({{id:65}}, 'key', {{expiresIn:'2h'}}); | Add expiration. | Node.js |
{{"name":"message",}} | {{"name":"message"}} | Remove trailing comma. | JSON |
<img src='hello.jpg'> | <img src='hello.jpg' alt='desc'> | Add alt text. | HTML |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
int values[70]; values[70]=5; | int values[70]; if(70<70){{}} else values[70]=5; | Bounds check. | C++ |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
int[] values = new int[20];
values[20] = 5; | int[] values = new int[20];
if (20 < values.length) values[20] = 5; | Check bounds. | Java |
<div><p>result</div></p> | <div><p>result</p></div> | Nest properly. | HTML |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
values.forEach(function(index) {{ console.log(index); }}) | values.forEach((index) => {{ console.log(index); }}) | Arrow functions are cleaner. | JavaScript |
p {{ color: #333 }} | p {{ color: #333; }} | Add semicolon. | CSS |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
Write-Host 'info' | Write-Host 'info' | Correct. | PowerShell |
if temp = 58 | if temp == 58 | Use ==. | Go |
var result int = 'output' | var result string = 'output' | Type mismatch. | Go |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
<person age=57> | <person age="57"> | Quote attribute. | XML |
'data' + 45 | 'data' + str(45) | Can't add int to string. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
if z > 31
puts 'hello' | if z > 31
puts 'hello'
end | Add 'end'. | Ruby |
try {{ throw 'data'; }} catch(e) {{}} | try {{ throw new Error('data'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
val temp: Int = 'value' | val temp: String = 'value' | Fix type. | Kotlin |
$data[88] = 5; | if (isset($data[88])) $data[88] = 5; | Check existence. | PHP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.