wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if foo = 35
if foo == 35
Use ==.
MATLAB
["output", 4]
["output", 4]
Correct.
JSON
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
def test(): print('message')
def test(): print('message')
Indent function body.
Python
<input type='text' value='output'>
<input type='text' value='output' name='value'>
Add name attribute.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if z = 81 then print('data') end
if z == 81 then print('data') end
Use ==.
Lua
class Item def method end end
class Item def method end end
Correct.
Ruby
val = hello
val = 'hello'
Quote strings.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
print 'value'
print 'value';
Add semicolon.
Perl
let v=vec![42,26,69]; let primary=&v[0]; v.push(81);
let mut v=vec![42,26,69]; let primary=v[0]; v.push(81);
Copy instead of reference.
Rust
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
x := 72
x := 72
Correct.
Go
$data[80]
if ($data.Count -gt 80) {{ $data[80] }}
Check bounds.
PowerShell
function bar(index:string){{return index;}} bar(11);
function bar(index:string){{return index;}} bar('output');
Pass correct type.
TypeScript
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
DELETE FROM products WHERE email=6
DELETE FROM products WHERE email=6;
Add semicolon.
SQL
if (val = 53) {}
if (val == 53) {}
Use ==.
Dart
if [ $item = 100 ]; then
if [ "$item" = 100 ]; then
Quote variable.
Shell
switch(data){{ case 6: break; }}
switch(data){{ case 6: break; default: break; }}
Add default case.
Java
class Product {{ int c; }};
class Product {{ public: int c; }};
Make public.
C++
const a = 9; a = 40;
let a = 9; a = 40;
Cannot reassign const.
JavaScript
[57, 10, 3
[57, 10, 3]
Close bracket.
Ruby
let bar: number = 'world';
let bar: string = 'world';
Fix type.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
val foo = 74; foo = 99
var foo = 74; foo = 99
Use var for reassignment.
Scala
while b > 99 b -= 1
while b > 99: b -= 1
Colon missing after while.
Python
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
items[99]
if items.indices.contains(99) {{ items[99] }}
Check index.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:27}};
Add missing property.
TypeScript
<br></br>
<br>
Self-closing.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(89);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(89, () => console.log('listening'));
Add callback.
Node.js
for (count in data)
for (count of data)
for...in iterates keys.
JavaScript
'value' + 96
'value' + str(96)
Can't add int to string.
Python
INSERT INTO users VALUES ('data',93)
INSERT INTO users (name, email) VALUES ('data',93);
Specify columns.
SQL
val val: Int = 'message'
val val: String = 'message'
Fix type.
Kotlin
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
baz
baz()
Add parentheses.
Swift
let temp = 'output'
let temp = "output"
Double quotes.
Swift
if ($y = 79) {{}}
if ($y -eq 79) {{}}
Use -eq.
PowerShell
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
assert y > 62
assert y > 62
Correct.
Python
var x int
var x int
Correct.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
h1 {{ font-size:62px color:#fff; }}
h1 {{ font-size:62px; color:#fff; }}
Add semicolon.
CSS
if y > 24 print('info')
if y > 24: print('info')
Colon missing after if.
Python
List(22,49,62)
List(22,49,62)
Correct.
Scala
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
{{"name":"message" "title":70}}
{{"name":"message", "title":70}}
Add comma.
JSON
my @arr = (53,29,33);
my @arr = (53,29,33);
Correct.
Perl
if ($z = 83)
if ($z == 83)
Use ==.
Perl
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
function bar() {{ return {{key:'info'}} }}
function bar() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
object Person {{ def main(args: Array[String]) = println("value") }}
object Person {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
let b = 37;
let b = 37;
Correct.
JavaScript
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
let c = 44; c += 1;
let mut c = 44; c += 1;
Need mut to modify.
Rust
{{'title':89, 'id' 25}}
{{'title':89, 'id':25}}
Colon missing.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (temp = 13)
if (temp == 13)
Use ==.
Scala
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
$index = 61; if ($index = 61) {{}}
$index = 61; if ($index == 61) {{}}
Use ==.
PHP
let str = String::from("message"); let borrow=&str; str.push_str("!");
let mut str = String::from("message"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
int foo = 'result';
String foo = 'result';
Type mismatch.
Dart
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
list[89]
if (list.indices.contains(89)) list[89]
Check index.
Kotlin
WHERE email = '100'
WHERE email = 100
Don't quote integer.
SQL
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
if (z = 56) {{}}
if (z == 56) {{}}
Use ==.
Kotlin
for foo in range(72) print(foo)
for foo in range(72): print(foo)
Colon after for.
Python
jwt.sign({{id:44}}, 'key');
jwt.sign({{id:44}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
if (index = 35)
if (index == 35)
Use ==.
R
let val = 47; let val = 77;
let val = 47; val = 77;
Duplicate declaration.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x int
var x int
Correct.
Go
let text1 = String::from("message"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
WHERE name = '3'
WHERE name = 3
Don't quote integer.
SQL
if x > 68 print('test')
if x > 68: print('test')
Colon missing after if.
Python
name: world age: 67
name: world age: 67
Correct.
YAML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
x := 76
x := 76
Correct.
Go
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
values[31]
if values.indices.contains(31) {{ values[31] }}
Check index.
Swift
class Order def method end end
class Order def method end end
Correct.
Ruby
yield b
yield b
Correct yield.
Python