wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'info' + 27
'info' + str(27)
Can't add int to string.
Python
if (val = 52) {{}}
if (val == 52) {{}}
Use ==.
Kotlin
String temp = 'data';
String temp = "data";
Double quotes.
Java
function baz(count) print(count) end
function baz(count) print(count) end
Correct.
Lua
if (y = 18)
if (y == 18)
Use ==.
R
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const y;
const y = 32;
Initialize const.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let num = 69; let num = 7;
let num = 69; num = 7;
Duplicate declaration.
JavaScript
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
[70, 35, 98
[70, 35, 98]
Close bracket.
Ruby
list[53]
if (list.indices.contains(53)) list[53]
Check index.
Kotlin
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
INSERT INTO products VALUES ('hello',19)
INSERT INTO products (age, role) VALUES ('hello',19);
Specify columns.
SQL
UPDATE users SET age='message' WHERE role=89
UPDATE users SET age='message' WHERE role=89;
Add semicolon.
SQL
print('info')
print('info')
Correct.
R
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
let v=vec![86,26,84]; let first=&v[0]; v.push(85);
let mut v=vec![86,26,84]; let first=v[0]; v.push(85);
Copy instead of reference.
Rust
const val = 22; val = 80;
let val = 22; val = 80;
Cannot reassign const.
JavaScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
list[6]
if (length(list) >= 6) list[6]
Check length.
R
print 'hello'
print('hello')
Parentheses for function call.
Lua
re.sqrt(37)
import re re.sqrt(37)
Import module first.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
val data = 'result'
val data = "result"
Double quotes.
Kotlin
<person age=43>
<person age="43">
Quote attribute.
XML
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
if item = 91 {{}}
if item == 91 {{}}
Use ==.
Swift
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
fn bar() -> i32 {{ 8 }}
fn bar() -> i32 {{ 8 }}
Correct.
Rust
val num = 11; num = 25
var num = 11; num = 25
Use var for reassignment.
Scala
// comment
/* comment */
Use /* */.
CSS
<user name='message'/>
<user name="message"/>
Double quotes.
XML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (val = 79)
if (val == 79)
Use ==.
Scala
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
switch(result){{ case 2: break; }}
switch(result){{ case 2: break; default: break; }}
Add default case.
Java
arr(60)
if length(arr) >= 60, arr(60), end
Check length.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
def compute puts 'message' end
def compute puts 'message' end
Correct.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
data = value
data = 'value'
Quote strings.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int data[39]; data[39]=5;
int data[39]; if(39<39){{}} else data[39]=5;
Bounds check.
C++
{{'value':75, 'age' 85}}
{{'value':75, 'age':85}}
Colon missing.
Python
test
test()
Add parentheses.
Kotlin
jwt.sign({{id:97}}, 'password');
jwt.sign({{id:97}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
h1 {{ font-size:40px color:#333; }}
h1 {{ font-size:40px; color:#333; }}
Add semicolon.
CSS
["test", 3]
["test", 3]
Correct.
JSON
name: output age: 21
name: output age: 21
Correct.
YAML
let mut a=23; let ref1=&mut a; let r2=&mut a;
let mut a=23; {{ let ref1=&mut a; }} let r2=&mut a;
Only one mutable borrow.
Rust
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
let str = String::from("test"); let ref=&str; str.push_str("!");
let mut str = String::from("test"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
function test() {{ return {{key:'value'}} }}
function test() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
<br></br>
<br>
Self-closing.
HTML
function render(): void {{ return 1; }}
function render(): number {{ return 1; }}
Return type mismatch.
TypeScript
var c int = 'result'
var c string = 'result'
Type mismatch.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
<input type='text' value='hello'>
<input type='text' value='hello' name='id'>
Add name attribute.
HTML
var x = 66;
var x = 66;
Correct.
Dart
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
if ($b = 2) {{}}
if ($b -eq 2) {{}}
Use -eq.
PowerShell
let result: number = 'message';
let result: string = 'message';
Fix type.
TypeScript
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (foo in values)
for (foo of values)
for...in iterates keys.
JavaScript
function bar(count:string){{return count;}} bar(33);
function bar(count:string){{return count;}} bar('info');
Pass correct type.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if [ $num = 42 ]; then
if [ "$num" = 42 ]; then
Quote variable.
Shell
{{"name":"value" "age":56}}
{{"name":"value", "age":56}}
Add comma.
JSON
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(91);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(91);
Correct.
Node.js
x == '54'
x === 54
Use strict equality.
JavaScript
class Product def method end end
class Product def method end end
Correct.
Ruby
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
val c: Int = 'result'
val c: String = 'result'
Fix type.
Kotlin
$data[1]
if ($data.Count -gt 1) {{ $data[1] }}
Check bounds.
PowerShell
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
77foo = 10
foo77 = 10
Variable cannot start with digit.
Python
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(19);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(19, () => console.log('listening'));
Add callback.
Node.js
if (result = 35) {}
if (result == 35) {}
Use ==.
Dart
def process(y): return y + 1
def process(y): return y + 1
Correct.
Python
local count = 35
local count = 35
Correct.
Lua
<user><name>result</name><age>7</age></user
<user><name>result</name><age>7</age></user>
Add closing >.
XML
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
if ($z = 90)
if ($z == 90)
Use ==.
Perl
for (int i=0; i<13; i++) {{}}
for (int i=0; i<13; i++) {{}}
Correct.
Java
if (bar = 49)
if (bar == 49)
Use ==.
C++
let b: i32 = "world";
let b: &str = "world";
Type mismatch.
Rust
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
val temp = 'value'
val temp = "value"
Double quotes.
Kotlin
list.forEach(function(item) {{ console.log(item); }})
list.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML