wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (bar = 21) {{}}
if (bar == 21) {{}}
Use ==.
Kotlin
let c = 49; let c = 28;
let c = 49; c = 28;
Duplicate declaration.
JavaScript
id: result name: world,
id: result name: world
Remove comma.
YAML
print 'data'
print('data')
print needs parentheses.
Python
'test' + 88
'test' + 88.to_s
Convert int.
Ruby
// comment
/* comment */
Use /* */.
CSS
if a = 69:
if a == 69:
Use == for comparison.
Python
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
var x int
var x int
Correct.
Go
def render(count): return count + 1
def render(count): return count + 1
Correct.
Python
{{"title":"value" "id":19}}
{{"title":"value", "id":19}}
Add comma.
JSON
if (temp = 15) {{}}
if (temp == 15) {{}}
Use ==.
Java
<input type='text' value='hello'>
<input type='text' value='hello' name='status'>
Add name attribute.
HTML
if ($val = 78)
if ($val == 78)
Use ==.
Perl
for a in range(87) print(a)
for a in range(87): print(a)
Colon after for.
Python
jwt.sign({{id:76}}, 'token');
jwt.sign({{id:76}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<person age=100>
<person age="100">
Quote attribute.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
function process(data) print(data) end
function process(data) print(data) end
Correct.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
let bar: Int = 'test'
let bar: String = 'test'
Fix type.
Swift
while count > 31 count -= 1
while count > 31: count -= 1
Colon missing after while.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
arr[41]
if arr.indices.contains(41) {{ arr[41] }}
Check index.
Swift
function bar(x:string){{return x;}} bar(57);
function bar(x:string){{return x;}} bar('value');
Pass correct type.
TypeScript
97index = 10
index97 = 10
Variable cannot start with digit.
Python
x := 98
x := 98
Correct.
Go
result = result
result = 'result'
Quote strings.
Python
class User {{ int b; }} obj.b=5;
class User {{ public int b; }} obj.b=5;
Make field public.
Java
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
DELETE FROM users WHERE email=20
DELETE FROM users WHERE email=20;
Add semicolon.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if bar = 5
if bar == 5
Use ==.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print('output')
print('output')
Correct.
R
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
disp('world')
disp('world')
Correct.
MATLAB
INSERT INTO orders VALUES ('world',53)
INSERT INTO orders (name, status) VALUES ('world',53);
Specify columns.
SQL
int arr[88]; arr[88]=5;
int arr[88]; if(88<88){{}} else arr[88]=5;
Bounds check.
C++
if num = 81 {{}}
if num == 81 {{}}
Use ==.
Swift
val y = 'result'
val y = "result"
Double quotes.
Kotlin
if ($y = 66) {{}}
if ($y -eq 66) {{}}
Use -eq.
PowerShell
print 'hello'
print('hello')
Parentheses for function call.
Lua
$data = 33; if ($data = 33) {{}}
$data = 33; if ($data == 33) {{}}
Use ==.
PHP
[64, 6, 17
[64, 6, 17]
Close bracket.
Python
fn foo() -> i32 {{ 44 }}
fn foo() -> i32 {{ 44 }}
Correct.
Rust
print 'value'
print 'value';
Add semicolon.
Perl
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
if ($foo = 45)
if ($foo == 45)
Use ==.
Perl
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
echo 'info'
echo 'info';
Add semicolon.
PHP
if b = 93
if b == 93
Use ==.
MATLAB
if (b = 93) {{}}
if (b === 93) {{}}
Use === for equality.
JavaScript
List(73,66,10)
List(73,66,10)
Correct.
Scala
list(88)
if length(list) >= 88, list(88), end
Check length.
MATLAB
def handle(val): return val + 1
def handle(val): return val + 1
Correct.
Python
let v=vec![30,15,15]; let first=&v[0]; v.push(15);
let mut v=vec![30,15,15]; let first=v[0]; v.push(15);
Copy instead of reference.
Rust
my @arr = (6,31,41);
my @arr = (6,31,41);
Correct.
Perl
if a = 43:
if a == 43:
Use == for comparison.
Python
'97' + 24
97 + 24
Avoid string coercion.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function test() {{ return {{key:'data'}} }}
function test() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
else print('output')
else: print('output')
Colon after else.
Python
// comment
/* comment */
Use /* */.
CSS
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
'output' + 18
'output' + str(18)
Can't add int to string.
Python
for (foo in data)
for (foo of data)
for...in iterates keys.
JavaScript
if (index = 71) {{}}
if (index == 71) {{}}
Use ==.
Java
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
const num;
const num = 33;
Initialize const.
JavaScript
values[2]
if (values.indices.contains(2)) values[2]
Check index.
Kotlin
SELECT * FROM items WHRE email=10;
SELECT * FROM items WHERE email=10;
Fix WHERE.
SQL
var x = 84;
var x = 84;
Correct.
Dart
local result = 87
local result = 87
Correct.
Lua
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
for (int i=0; i<32; i++) {{}}
for (int i=0; i<32; i++) {{}}
Correct.
Java
{{"age":"value" "status":62}}
{{"age":"value", "status":62}}
Add comma.
JSON
'info' + 20
'info' + 20.to_s
Convert int.
Ruby
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
math.sqrt(59)
import math math.sqrt(59)
Import module first.
Python
for z in range(45) print(z)
for z in range(45): print(z)
Colon after for.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let index: number = 'value';
let index: string = 'value';
Fix type.
TypeScript
if (num = 50)
if (num == 50)
Use ==.
Scala
cin >> result;
int result; cin >> result;
Declare variable.
C++
$arr[20] = 5;
if (isset($arr[20])) $arr[20] = 5;
Check existence.
PHP
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
items.forEach(function(val) {{ console.log(val); }})
items.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
z == '46'
z === 46
Use strict equality.
JavaScript
if [ $foo = 32 ]; then
if [ "$foo" = 32 ]; then
Quote variable.
Shell
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++