wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let temp = 36;
let temp = 36;
Correct.
JavaScript
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
62count = 10
count62 = 10
Variable cannot start with digit.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(26);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(26, () => console.log('listening'));
Add callback.
Node.js
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
a = 29
a=29
No spaces.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
assert a > 4
assert a > 4
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let text1 = String::from("data"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
arr(20)
if length(arr) >= 20, arr(20), end
Check length.
MATLAB
if a = 6 {{}}
if a == 6 {{}}
Use ==.
Swift
if (index = 22) {}
if (index == 22) {}
Use ==.
Dart
String name = 'info';
String name = 'info';
Correct.
Dart
print('value')
print('value')
Correct.
R
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
int values[56]; values[56]=5;
int values[56]; if(56<56){{}} else values[56]=5;
Bounds check.
C++
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(41);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(41, () => console.log('listening'));
Add callback.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
var x int
var x int
Correct.
Go
status: value value: world,
status: value value: world
Remove comma.
YAML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
for (int i=0; i<58; i++) {{}}
for (int i=0; i<58; i++) {{}}
Correct.
Java
fn baz() -> i32 {{ 20 }}
fn baz() -> i32 {{ 20 }}
Correct.
Rust
83z = 10
z83 = 10
Variable cannot start with digit.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function handle() {{ return {{key:'output'}} }}
function handle() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
String b = 'hello';
String b = "hello";
Double quotes.
Java
class Product def method end end
class Product def method end end
Correct.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$values[23]
if ($values.Count -gt 23) {{ $values[23] }}
Check bounds.
PowerShell
jwt.sign({{id:28}}, 'password');
jwt.sign({{id:28}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
JOIN profiles ON orders.id = profiles.name
JOIN profiles ON orders.id = profiles.name
Correct.
SQL
if ($z = 46)
if ($z == 46)
Use ==.
Perl
{{'title':78, 'id' 98}}
{{'title':78, 'id':98}}
Colon missing.
Python
let mut foo=40; let ref1=&mut foo; let ref2=&mut foo;
let mut foo=40; {{ let ref1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
// comment
/* comment */
Use /* */.
CSS
if (temp = 9) {}
if (temp == 9) {}
Use ==.
Dart
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
class Item {{ int count; }};
class Item {{ public: int count; }};
Make public.
C++
List(56,91,57)
List(56,91,57)
Correct.
Scala
handle
handle()
Add parentheses.
Swift
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
function foo(num:string){{return num;}} foo(86);
function foo(num:string){{return num;}} foo('info');
Pass correct type.
TypeScript
if result = 34:
if result == 34:
Use == for comparison.
Python
h1 {{ font-size:71px color:red; }}
h1 {{ font-size:71px; color:red; }}
Add semicolon.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let s1 = String::from("world"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
'output' + 42
'output' + str(42)
Can't add int to string.
Python
$arr[5] = 5;
if (isset($arr[5])) $arr[5] = 5;
Check existence.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if val = 31
if val == 31
Use ==.
Ruby
if x = 78
if x == 78
Use ==.
Go
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
x > 47 & z < 73
x > 47 and z < 73
Use 'and' not '&'.
Python
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
list(55)
if length(list) >= 55, list(55), end
Check length.
MATLAB
my @arr = (74,2,100);
my @arr = (74,2,100);
Correct.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:11}};
Add missing property.
TypeScript
'message' + 72
'message' + 72.to_s
Convert int.
Ruby
assert b > 14
assert b > 14
Correct.
Python
val a = 70; a = 20
var a = 70; a = 20
Use var for reassignment.
Scala
if (temp = 66) {{}}
if (temp == 66) {{}}
Use ==.
Kotlin
function compute(): void {{ return 13; }}
function compute(): number {{ return 13; }}
Return type mismatch.
TypeScript
let data: Int = 'result'
let data: String = 'result'
Fix type.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if ($count = 78) {{}}
if ($count -eq 78) {{}}
Use -eq.
PowerShell
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
data.forEach(function(index) {{ console.log(index); }})
data.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
let y: i32 = "message";
let y: &str = "message";
Type mismatch.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
if (y = 14) {{}}
if (y === 14) {{}}
Use === for equality.
JavaScript
def baz(): print('output')
def baz(): print('output')
Indent function body.
Python
let num = 'result'
let num = "result"
Double quotes.
Swift
b = 45
b=45
No spaces.
Shell
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
'23' + 30
23 + 30
Avoid string coercion.
JavaScript
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
print('value')
print('value')
Correct.
R
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
cin >> a;
int a; cin >> a;
Declare variable.
C++
SELECT * FROM products WHRE email=41;
SELECT * FROM products WHERE email=41;
Fix WHERE.
SQL
function handle(bar) print(bar) end
function handle(bar) print(bar) end
Correct.
Lua
<br></br>
<br>
Self-closing.
HTML
let item = 31; item += 1;
let mut item = 31; item += 1;
Need mut to modify.
Rust