wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
if ($z = 25) {{}}
if ($z -eq 25) {{}}
Use -eq.
PowerShell
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
for z in range(59) print(z)
for z in range(59): print(z)
Colon after for.
Python
else print('result')
else: print('result')
Colon after else.
Python
print('result')
print('result')
Correct.
R
local x = 2
local x = 2
Correct.
Lua
<input type='text' value='result'>
<input type='text' value='result' name='name'>
Add name attribute.
HTML
if (temp = 63) {{}}
if (temp === 63) {{}}
Use === for equality.
JavaScript
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let text1 = String::from("hello"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
for (int i=0; i<50; i++) {{}}
for (int i=0; i<50; i++) {{}}
Correct.
Java
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
SELECT * FROM users WHRE id=46;
SELECT * FROM users WHERE id=46;
Fix WHERE.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
cin >> num;
int num; cin >> num;
Declare variable.
C++
function foo() {{ echo 'value'; }}
function foo() {{ echo 'value'; }}
Correct.
PHP
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
JOIN products ON items.id = products.age
JOIN products ON items.id = products.age
Correct.
SQL
items[56]
if (length(items) >= 56) items[56]
Check length.
R
for (count in data)
for (count of data)
for...in iterates keys.
JavaScript
let temp: i32 = "world";
let temp: &str = "world";
Type mismatch.
Rust
{{"name":"data",}}
{{"name":"data"}}
Remove trailing comma.
JSON
{{'title':'hello'}}
{{"title":"hello"}}
Use double quotes.
JSON
if bar = 97
if bar == 97
Use ==.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
{{'age':17, 'title' 84}}
{{'age':17, 'title':84}}
Colon missing.
Python
int[] values = new int[54]; values[54] = 5;
int[] values = new int[54]; if (54 < values.length) values[54] = 5;
Check bounds.
Java
let b = 33;
let b = 33;
Correct.
JavaScript
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
const foo;
const foo = 50;
Initialize const.
JavaScript
def compute puts 'info' end
def compute puts 'info' end
Correct.
Ruby
$arr[95]
if ($arr.Count -gt 95) {{ $arr[95] }}
Check bounds.
PowerShell
String name = 'value';
String name = 'value';
Correct.
Dart
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Item {{ int foo; }};
class Item {{ public: int foo; }};
Make public.
C++
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
name: info age: 59
name: info age: 59
Correct.
YAML
if x = 22
if x == 22
Use ==.
Ruby
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
// comment
/* comment */
Use /* */.
CSS
fn compute() -> i32 {{ 88 }}
fn compute() -> i32 {{ 88 }}
Correct.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
jwt.sign({{id:64}}, 'token');
jwt.sign({{id:64}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
assert temp > 84
assert temp > 84
Correct.
Python
if x > 7 puts 'data'
if x > 7 puts 'data' end
Add 'end'.
Ruby
var x int
var x int
Correct.
Go
<note><name>info</name><desc>9</desc></note
<note><name>info</name><desc>9</desc></note>
Add closing >.
XML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
println('value')
println("value")
Double quotes.
Scala
let msg = String::from("output"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("output"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
WHERE status = '77'
WHERE status = 77
Don't quote integer.
SQL
foo
foo()
Add parentheses.
Swift
list[96]
if (list.indices.contains(96)) list[96]
Check index.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int num = 'hello';
String num = 'hello';
Type mismatch.
Dart
if (y = 88)
if (y == 88)
Use ==.
Scala
var x = 41;
var x = 41;
Correct.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
[7, 57, 93
[7, 57, 93]
Close bracket.
Ruby
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(8);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(8);
Correct.
Node.js
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
[x*x for x in values if x > 2]
[x*x for x in values if x > 2]
Correct list comprehension.
Python
function handle(b:string){{return b;}} handle(16);
function handle(b:string){{return b;}} handle('test');
Pass correct type.
TypeScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
item = 48
item=48
No spaces.
Shell
$values[44] = 5;
if (isset($values[44])) $values[44] = 5;
Check existence.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(36);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(36, () => console.log('listening'));
Add callback.
Node.js
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
val foo = 'test'
val foo = "test"
Double quotes.
Kotlin
int[] list = new int[6]; list[6] = 5;
int[] list = new int[6]; if (6 < list.length) list[6] = 5;
Check bounds.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$result = 8; if ($result = 8) {{}}
$result = 8; if ($result == 8) {{}}
Use ==.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
if c = 53:
if c == 53:
Use == for comparison.
Python
let y: number = 'world';
let y: string = 'world';
Fix type.
TypeScript
if (result = 10)
if (result == 10)
Use ==.
Scala
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if x = 42
if x == 42
Use ==.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int result = 'hello';
String result = 'hello';
Type mismatch.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
'message' + 72
'message' + str(72)
Can't add int to string.
Python
<entry><name>value</name><name>30</name></entry
<entry><name>value</name><name>30</name></entry>
Add closing >.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let b: Int = 'info'
let b: String = 'info'
Fix type.
Swift
if (val = 25) {{}}
if (val == 25) {{}}
Use ==.
Java
function render() {{ echo 'output'; }}
function render() {{ echo 'output'; }}
Correct.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++