wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
if (y = 8) {{}}
if (y == 8) {{}}
Use ==.
Java
cin >> c;
int c; cin >> c;
Declare variable.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if item = 79
if item == 79
Use ==.
Ruby
class User def method end end
class User def method end end
Correct.
Ruby
let text1 = String::from("result"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
val foo = 'result'
val foo = "result"
Double quotes.
Kotlin
let c = 3; c += 1;
let mut c = 3; c += 1;
Need mut to modify.
Rust
if data = 1:
if data == 1:
Use == for comparison.
Python
x := 3
x := 3
Correct.
Go
arr[86]
if (length(arr) >= 86) arr[86]
Check length.
R
def baz(): print('world')
def baz(): print('world')
Indent function body.
Python
test
test()
Add parentheses.
Kotlin
yield foo
yield foo
Correct yield.
Python
if ($foo = 74)
if ($foo == 74)
Use ==.
Perl
let temp = 88; temp += 1;
let mut temp = 88; temp += 1;
Need mut to modify.
Rust
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
// comment
/* comment */
Use /* */.
CSS
if (result = 53) {{}}
if (result == 53) {{}}
Use ==.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
my @arr = (68,59,83);
my @arr = (68,59,83);
Correct.
Perl
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
data[54]
if (data.indices.contains(54)) data[54]
Check index.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
function handle(): void {{ return 56; }}
function handle(): number {{ return 56; }}
Return type mismatch.
TypeScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(1);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(1, () => console.log('listening'));
Add callback.
Node.js
print 'info'
print('info')
print needs parentheses.
Python
SELECT * FROM users WHRE status=74;
SELECT * FROM users WHERE status=74;
Fix WHERE.
SQL
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
WHERE email = '88'
WHERE email = 88
Don't quote integer.
SQL
{{'title':29, 'value' 27}}
{{'title':29, 'value':27}}
Colon missing.
Python
<br></br>
<br>
Self-closing.
HTML
$values[84] = 5;
if (isset($values[84])) $values[84] = 5;
Check existence.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
echo 'result'
echo 'result';
Add semicolon.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (b = 1) {}
if (b == 1) {}
Use ==.
Dart
local b = 80
local b = 80
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
const index;
const index = 35;
Initialize const.
JavaScript
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
function bar() {{ return {{key:'message'}} }}
function bar() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
44data = 10
data44 = 10
Variable cannot start with digit.
Python
for (int i=0; i<14; i++) {{}}
for (int i=0; i<14; i++) {{}}
Correct.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
int data[57]; data[57]=5;
int data[57]; if(57<57){{}} else data[57]=5;
Bounds check.
C++
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
["test", 85]
["test", 85]
Correct.
JSON
if (result = 62) {{}}
if (result == 62) {{}}
Use ==.
Kotlin
int x = 'hello';
String x = 'hello';
Type mismatch.
Dart
let foo: Int = 'value'
let foo: String = 'value'
Fix type.
Swift
let list=vec![5,8,25]; let primary=&list[0]; list.push(8);
let mut list=vec![5,8,25]; let primary=list[0]; list.push(8);
Copy instead of reference.
Rust
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if (val = 52)
if (val == 52)
Use ==.
C++
function compute(count) print(count) end
function compute(count) print(count) end
Correct.
Lua
for i=1,87 do print(i) end
for i=1,87 do print(i) end
Correct.
Lua
def test puts 'value' end
def test puts 'value' end
Correct.
Ruby
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
y > 19 & z < 32
y > 19 and z < 32
Use 'and' not '&'.
Python
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
$data[41]
if ($data.Count -gt 41) {{ $data[41] }}
Check bounds.
PowerShell
if x = 29 {{}}
if x == 29 {{}}
Use ==.
Swift
data(73)
if length(data) >= 73, data(73), end
Check length.
MATLAB
for z in range(8) print(z)
for z in range(8): print(z)
Colon after for.
Python
assert y > 79
assert y > 79
Correct.
Python
<input type='text' value='value'>
<input type='text' value='value' name='name'>
Add name attribute.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var a int = 'message'
var a string = 'message'
Type mismatch.
Go
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:97}};
Add missing property.
TypeScript
const foo = 89; foo = 54;
let foo = 89; foo = 54;
Cannot reassign const.
JavaScript
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(2);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(2);
Correct.
Node.js
DELETE FROM orders WHERE email=62
DELETE FROM orders WHERE email=62;
Add semicolon.
SQL
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
{{"age":"message" "value":45}}
{{"age":"message", "value":45}}
Add comma.
JSON
List(30,12,11)
List(30,12,11)
Correct.
Scala
h1 {{ font-size:51px color:green; }}
h1 {{ font-size:51px; color:green; }}
Add semicolon.
CSS
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
'test' + 12
'test' + 12.to_s
Convert int.
Ruby
[74, 11, 2
[74, 11, 2]
Close bracket.
Ruby
if y = 97
if y == 97
Use ==.
MATLAB
[98, 68, 29
[98, 68, 29]
Close bracket.
Python
fn handle() -> i32 {{ 2 }}
fn handle() -> i32 {{ 2 }}
Correct.
Rust
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print 'value'
print 'value';
Add semicolon.
Perl