wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let msg = String::from("info"); let r=&msg; msg.push_str("!");
let mut msg = String::from("info"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
for (a in values)
for (a of values)
for...in iterates keys.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
cin >> num;
int num; cin >> num;
Declare variable.
C++
function process(temp) print(temp) end
function process(temp) print(temp) end
Correct.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(26);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(26, () => console.log('listening'));
Add callback.
Node.js
if foo = 28 then print('test') end
if foo == 28 then print('test') end
Use ==.
Lua
re.sqrt(74)
import re re.sqrt(74)
Import module first.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
<person age=21>
<person age="21">
Quote attribute.
XML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
var x int
var x int
Correct.
Go
var x = 57;
var x = 57;
Correct.
Dart
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
class User {{ int num; }} obj.num=5;
class User {{ public int num; }} obj.num=5;
Make field public.
Java
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
switch(val){{ case 52: break; }}
switch(val){{ case 52: break; default: break; }}
Add default case.
Java
{{'title':92, 'age' 26}}
{{'title':92, 'age':26}}
Colon missing.
Python
print 'result'
print('result')
print needs parentheses.
Python
[88, 31, 60
[88, 31, 60]
Close bracket.
Python
if (c = 35) {}
if (c == 35) {}
Use ==.
Dart
let x: i32 = "output";
let x: &str = "output";
Type mismatch.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let vec=vec![47,13,10]; let primary=&vec[0]; vec.push(39);
let mut vec=vec![47,13,10]; let primary=vec[0]; vec.push(39);
Copy instead of reference.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
let c: Int = 'output'
let c: String = 'output'
Fix type.
Swift
UPDATE orders SET name='info' WHERE role=31
UPDATE orders SET name='info' WHERE role=31;
Add semicolon.
SQL
else print('value')
else: print('value')
Colon after else.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if bar > 10 print('world')
if bar > 10: print('world')
Colon missing after if.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let str1 = String::from("world"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
int values[73]; values[73]=5;
int values[73]; if(73<73){{}} else values[73]=5;
Bounds check.
C++
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
def handle puts 'message' end
def handle puts 'message' end
Correct.
Ruby
local foo = 56
local foo = 56
Correct.
Lua
if (a = 38) {{}}
if (a == 38) {{}}
Use ==.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
val b: Int = 'data'
val b: String = 'data'
Fix type.
Kotlin
foo
foo()
Add parentheses.
Kotlin
val data = 63; data = 56
var data = 63; data = 56
Use var for reassignment.
Scala
var data int = 'test'
var data string = 'test'
Type mismatch.
Go
if (b = 13)
if (b == 13)
Use ==.
C++
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:36}};
Add missing property.
TypeScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let s = String::from("output"); let ref=&s; s.push_str("!");
let mut s = String::from("output"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
if (index = 73)
if (index == 73)
Use ==.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
val count = 'result'
val count = "result"
Double quotes.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let a = 'world'
let a = "world"
Double quotes.
Swift
c = 96
c=96
No spaces.
Shell
if (num = 5) {{}}
if (num == 5) {{}}
Use ==.
Kotlin
let item = 31;
let item = 31;
Correct.
JavaScript
$values[64]
if ($values.Count -gt 64) {{ $values[64] }}
Check bounds.
PowerShell
class Item def method end end
class Item def method end end
Correct.
Ruby
if (b = 5) {{}}
if (b === 5) {{}}
Use === for equality.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(24);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(24);
Correct.
Node.js
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let a: number = 'message';
let a: string = 'message';
Fix type.
TypeScript
<input type='text' value='world'>
<input type='text' value='world' name='status'>
Add name attribute.
HTML
$val = 83; if ($val = 83) {{}}
$val = 83; if ($val == 83) {{}}
Use ==.
PHP
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
const c;
const c = 62;
Initialize const.
JavaScript
list[49]
if (length(list) >= 49) list[49]
Check length.
R
list.forEach(function(b) {{ console.log(b); }})
list.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
String name = 'output';
String name = 'output';
Correct.
Dart
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
<person name='output'/>
<person name="output"/>
Double quotes.
XML
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
id: value title: world,
id: value title: world
Remove comma.
YAML
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
let b = 18; let b = 12;
let b = 18; b = 12;
Duplicate declaration.
JavaScript
function foo(a:string){{return a;}} foo(93);
function foo(a:string){{return a;}} foo('test');
Pass correct type.
TypeScript
if ($c = 15) {{}}
if ($c -eq 15) {{}}
Use -eq.
PowerShell
int[] items = new int[29]; items[29] = 5;
int[] items = new int[29]; if (29 < items.length) items[29] = 5;
Check bounds.
Java
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
function test() {{ echo 'output'; }}
function test() {{ echo 'output'; }}
Correct.
PHP
echo 'output'
echo 'output';
Add semicolon.
PHP
print('message')
print('message')
Correct.
R
SELECT * FROM products WHRE name=100;
SELECT * FROM products WHERE name=100;
Fix WHERE.
SQL
<br></br>
<br>
Self-closing.
HTML
println('data')
println("data")
Double quotes.
Scala
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
arr[50]
if (arr.indices.contains(50)) arr[50]
Check index.
Kotlin
def render(temp): return temp + 1
def render(temp): return temp + 1
Correct.
Python
jwt.sign({{id:30}}, 'key');
jwt.sign({{id:30}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
["value", 2]
["value", 2]
Correct.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java